Blender  V3.3
rigidbody_world.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "DNA_object_types.h"
13 #include "DNA_rigidbody_types.h"
14 #include "DNA_scene_types.h"
15 
16 #ifdef WITH_BULLET
17 # include "RBI_api.h"
18 #endif
19 
20 #include "BKE_context.h"
21 #include "BKE_main.h"
22 #include "BKE_report.h"
23 #include "BKE_rigidbody.h"
24 
25 #include "DEG_depsgraph.h"
26 #include "DEG_depsgraph_build.h"
27 
28 #include "RNA_access.h"
29 
30 #include "WM_api.h"
31 #include "WM_types.h"
32 
33 #include "ED_screen.h"
34 
35 #include "physics_intern.h"
36 
37 /* ********************************************** */
38 /* API */
39 
40 /* check if there is an active rigid body world */
42 {
44  return (scene && scene->rigidbody_world);
45 }
47 {
49  return (scene && scene->rigidbody_world == NULL);
50 }
51 
52 /* ********************************************** */
53 /* OPERATORS - Management */
54 
55 /* ********** Add RigidBody World **************** */
56 
58 {
59  Main *bmain = CTX_data_main(C);
61  RigidBodyWorld *rbw;
62 
64  // BKE_rigidbody_validate_sim_world(scene, rbw, false);
65  scene->rigidbody_world = rbw;
66 
67  /* Full rebuild of DEG! */
70 
71  return OPERATOR_FINISHED;
72 }
73 
75 {
76  /* identifiers */
77  ot->idname = "RIGIDBODY_OT_world_add";
78  ot->name = "Add Rigid Body World";
79  ot->description = "Add Rigid Body simulation world to the current scene";
80 
81  /* callbacks */
84 
85  /* flags */
87 }
88 
89 /* ********** Remove RigidBody World ************* */
90 
92 {
93  Main *bmain = CTX_data_main(C);
96 
97  /* sanity checks */
98  if (ELEM(NULL, scene, rbw)) {
99  BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to remove");
100  return OPERATOR_CANCELLED;
101  }
102 
104 
105  /* Full rebuild of DEG! */
108 
109  /* done */
110  return OPERATOR_FINISHED;
111 }
112 
114 {
115  /* identifiers */
116  ot->idname = "RIGIDBODY_OT_world_remove";
117  ot->name = "Remove Rigid Body World";
118  ot->description = "Remove Rigid Body simulation world from the current scene";
119 
120  /* callbacks */
123 
124  /* flags */
126 }
127 
128 /* ********************************************** */
129 /* UTILITY OPERATORS */
130 
131 /* ********** Export RigidBody World ************* */
132 
134 {
137  char path[FILE_MAX];
138 
139  /* sanity checks */
140  if (ELEM(NULL, scene, rbw)) {
141  BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to export");
142  return OPERATOR_CANCELLED;
143  }
144  if (rbw->shared->physics_world == NULL) {
145  BKE_report(
146  op->reports, RPT_ERROR, "Rigid Body World has no associated physics data to export");
147  return OPERATOR_CANCELLED;
148  }
149 
150  RNA_string_get(op->ptr, "filepath", path);
151 #ifdef WITH_BULLET
153 #endif
154  return OPERATOR_FINISHED;
155 }
156 
158 {
159  if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
160  RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
161  }
162 
163  if (RNA_struct_property_is_set(op->ptr, "filepath")) {
164  return rigidbody_world_export_exec(C, op);
165  }
166 
167  /* TODO: use the actual rigidbody world's name + .bullet instead of this temp crap */
168  RNA_string_set(op->ptr, "filepath", "rigidbodyworld_export.bullet");
170 
171  return OPERATOR_RUNNING_MODAL;
172 }
173 
175 {
176  /* identifiers */
177  ot->idname = "RIGIDBODY_OT_world_export";
178  ot->name = "Export Rigid Body World";
179  ot->description =
180  "Export Rigid Body world to simulator's own fileformat (i.e. '.bullet' for Bullet Physics)";
181 
182  /* callbacks */
186 
187  /* flags */
189 
190  /* properties */
193  FILE_SPECIAL,
194  FILE_SAVE,
198 }
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
API for Blender-side Rigid Body stuff.
void BKE_rigidbody_free_world(struct Scene *scene)
Definition: rigidbody.c:90
struct RigidBodyWorld * BKE_rigidbody_create_world(struct Scene *scene)
Definition: rigidbody.c:2300
#define FILE_MAX
#define UNUSED(x)
#define ELEM(...)
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
@ FILE_SORT_DEFAULT
@ FILE_SPECIAL
@ FILE_TYPE_FOLDER
@ FILE_DEFAULTDISPLAY
@ USER_RELPATHS
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
Rigid Body API for interfacing with external Physics Engines.
#define C
Definition: RandGen.cpp:25
@ WM_FILESEL_RELPATH
Definition: WM_api.h:752
@ FILE_SAVE
Definition: WM_api.h:765
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
void RIGIDBODY_OT_world_remove(wmOperatorType *ot)
static int rigidbody_world_add_exec(bContext *C, wmOperator *UNUSED(op))
static bool ED_rigidbody_world_active_poll(bContext *C)
static int rigidbody_world_export_exec(bContext *C, wmOperator *op)
static int rigidbody_world_remove_exec(bContext *C, wmOperator *op)
void RIGIDBODY_OT_world_export(wmOperatorType *ot)
void RIGIDBODY_OT_world_add(wmOperatorType *ot)
static int rigidbody_world_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static bool ED_rigidbody_world_add_poll(bContext *C)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:5155
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:4874
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:5116
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5301
Definition: BKE_main.h:121
struct RigidBodyWorld_Shared * shared
struct RigidBodyWorld * rigidbody_world
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_fileselect(bContext *C, wmOperator *op)
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)