Эх сурвалжийг харах

Set physics properties on a PhysicsMaterial. (#365)

* Don't set friction/bounce on KinematicBody.

These are properties only of Rigid and Static bodies.

* Set physics properties on a PhysicsMaterial.

```
The method set_friction has been deprecated and will be removed in the future, use physics material instead.
The method set_bounce has been deprecated and will be removed in the future, use physics material instead.
```

Fixes #364.
Ryan Roden-Corrent 4 жил өмнө
parent
commit
27ffa28078

+ 8 - 3
io_scene_godot/converters/physics.py

@@ -219,9 +219,14 @@ def export_physics_controller(escn_file, export_settings, node,
 
     phys_obj = NodeTemplate(phys_name, phys_controller, parent_gd_node)
 
-    #  OPTIONS FOR ALL PHYSICS TYPES
-    phys_obj['friction'] = rbd.friction
-    phys_obj['bounce'] = rbd.restitution
+    if phys_controller != 'KinematicBody':
+        physics_mat = InternalResource(
+            "PhysicsMaterial", node.name + "PhysicsMaterial"
+        )
+        physics_mat['friction'] = rbd.friction
+        physics_mat['bounce'] = rbd.restitution
+        rid = escn_file.force_add_internal_resource(physics_mat)
+        phys_obj['physics_material_override'] = "SubResource({})".format(rid)
 
     col_groups = 0
     for offset, flag in enumerate(rbd.collision_collections):

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 10 - 4
tests/reference_exports/action_animation/physics_animation.escn


+ 11 - 6
tests/reference_exports/armature/armature_with_physics.escn

@@ -1,11 +1,17 @@
 [gd_scene load_steps=1 format=2]
 
-[sub_resource id=1 type="ConvexPolygonShape"]
+[sub_resource id=1 type="PhysicsMaterial"]
+
+resource_name = "PhysicsPhysicsMaterial"
+friction = 0.5
+bounce = 0.0
+
+[sub_resource id=2 type="ConvexPolygonShape"]
 
 resource_name = "Cube002"
 points = PoolVector3Array(-0.8, -0.8, -1.2, -0.8, -0.8, 1.2, -0.8, 0.8, -1.2, -0.8, 0.8, 1.2, 0.8, -0.8, -1.2, 0.8, -0.8, 1.2, 0.8, 0.8, -1.2, 0.8, 0.8, 1.2)
 
-[sub_resource id=2 type="ArrayMesh"]
+[sub_resource id=3 type="ArrayMesh"]
 
 resource_name = "Cube001"
 surfaces/0 = {
@@ -28,8 +34,7 @@ surfaces/0 = {
 
 [node name="PhysicsPhysics" type="RigidBody" parent="."]
 
-friction = 0.5
-bounce = 0.0
+physics_material_override = SubResource(1)
 transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.2, 0.0)
 collision_layer = 1
 collision_mask = 1
@@ -41,7 +46,7 @@ sleeping = false
 [node name="PhysicsCollision" type="CollisionShape" parent="PhysicsPhysics"]
 
 transform = Transform(1.0, 0.0, 0.0, 0.0, -4.37114e-08, 1.0, 0.0, -1.0, -4.37114e-08, 0.0, 0.0, 0.0)
-shape = SubResource(1)
+shape = SubResource(2)
 
 [node name="Rig" type="Skeleton" parent="PhysicsPhysics/PhysicsCollision"]
 
@@ -86,7 +91,7 @@ bones/5/bound_children = []
 
 [node name="Mesh" type="MeshInstance" parent="PhysicsPhysics/PhysicsCollision/Rig"]
 
-mesh = SubResource(2)
+mesh = SubResource(3)
 visible = true
 transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 skeleton = NodePath("..:")

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 15 - 3
tests/reference_exports/mesh/physics.escn


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно