-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Inspector V2 Physics properties #16800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a912f46
Inspector V2 Physics
CedricGuillemet f824d89
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
CedricGuillemet 5ff0d0f
edit
CedricGuillemet 3ee5b46
damping + velocities
CedricGuillemet 2d35bc1
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
CedricGuillemet 862fad3
PR feedback
CedricGuillemet a47e629
Merge master
ryantrem 155e3ae
Remove nested PropertyLine since it is not currently well supported
ryantrem 82dbf6b
Merge master
ryantrem c4e39e7
Fix re-render loop
ryantrem d2fbbdb
Flatten AccordionSectionContent
ryantrem b4913d3
Show 'no physics body' when there is no physics body, and handle it d…
ryantrem af89e86
Roll back accidental change
ryantrem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/dev/inspector-v2/src/components/properties/physicsProperties.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import type { FunctionComponent } from "react"; | ||
|
||
import type { PhysicsBody } from "core/index"; | ||
import type { DropdownOption } from "shared-ui-components/fluent/primitives/dropdown"; | ||
|
||
import { useCallback } from "react"; | ||
|
||
import { Vector3 } from "core/Maths/math.vector"; | ||
import { PhysicsMotionType, PhysicsPrestepType } from "core/Physics/v2/IPhysicsEnginePlugin"; | ||
import { NumberDropdownPropertyLine } from "shared-ui-components/fluent/hoc/dropdownPropertyLine"; | ||
import { FloatInputPropertyLine } from "shared-ui-components/fluent/hoc/inputPropertyLine"; | ||
import { Vector3PropertyLine } from "shared-ui-components/fluent/hoc/vectorPropertyLine"; | ||
import { useVector3Property } from "../../hooks/compoundPropertyHooks"; | ||
import { useInterceptObservable } from "../../hooks/instrumentationHooks"; | ||
import { useObservableState } from "../../hooks/observableHooks"; | ||
|
||
import "core/Physics/v2/physicsEngineComponent"; | ||
|
||
const MotionOptions = [ | ||
{ label: "Static", value: PhysicsMotionType.STATIC }, | ||
{ label: "Animated", value: PhysicsMotionType.ANIMATED }, | ||
{ label: "Dynamic", value: PhysicsMotionType.DYNAMIC }, | ||
] as const satisfies readonly DropdownOption[]; | ||
|
||
const PrestepOptions = [ | ||
{ label: "Disabled", value: PhysicsPrestepType.DISABLED }, | ||
{ label: "Teleport", value: PhysicsPrestepType.TELEPORT }, | ||
{ label: "Action", value: PhysicsPrestepType.ACTION }, | ||
] as const satisfies readonly DropdownOption[]; | ||
|
||
/** | ||
* Physics properties | ||
* @param props transform node | ||
* @returns controls | ||
*/ | ||
export const PhysicsBodyProperties: FunctionComponent<{ physicsBody: PhysicsBody }> = (props) => { | ||
const { physicsBody } = props; | ||
|
||
const massProperties = useObservableState( | ||
useCallback(() => physicsBody.getMassProperties(), [physicsBody]), | ||
useInterceptObservable("function", physicsBody, "setMassProperties") | ||
); | ||
|
||
const centerOfMass = useVector3Property(massProperties, "centerOfMass") ?? Vector3.Zero(); | ||
ryantrem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const inertia = useVector3Property(massProperties, "inertia") ?? Vector3.Zero(); | ||
|
||
// Get current damping values | ||
const linearDamping = useObservableState(() => physicsBody.getLinearDamping(), useInterceptObservable("function", physicsBody, "setLinearDamping")); | ||
const angularDamping = useObservableState(() => physicsBody.getAngularDamping(), useInterceptObservable("function", physicsBody, "setAngularDamping")); | ||
|
||
// Get motion and prestep types | ||
const motionType = useObservableState(() => physicsBody.getMotionType(), useInterceptObservable("function", physicsBody, "setMotionType")); | ||
const prestepType = useObservableState(() => physicsBody.getPrestepType(), useInterceptObservable("function", physicsBody, "setPrestepType")); | ||
|
||
// Get current velocities | ||
const linearVelocity = useObservableState( | ||
useCallback(() => physicsBody.getLinearVelocity(), [physicsBody]), | ||
useInterceptObservable("function", physicsBody, "setLinearVelocity") | ||
); | ||
const angularVelocity = useObservableState( | ||
useCallback(() => physicsBody.getAngularVelocity(), [physicsBody]), | ||
useInterceptObservable("function", physicsBody, "setAngularVelocity") | ||
); | ||
|
||
return ( | ||
<> | ||
<NumberDropdownPropertyLine | ||
key="MotionType" | ||
label="Motion Type" | ||
options={MotionOptions} | ||
value={motionType} | ||
onChange={(value) => { | ||
return physicsBody.setMotionType(value as PhysicsMotionType); | ||
}} | ||
/> | ||
<NumberDropdownPropertyLine | ||
label="Prestep Type" | ||
options={PrestepOptions} | ||
value={prestepType} | ||
onChange={(value) => { | ||
return physicsBody.setPrestepType(value as PhysicsPrestepType); | ||
}} | ||
/> | ||
{/* Linear Damping */} | ||
<FloatInputPropertyLine | ||
label="Linear Damping" | ||
min={0} | ||
max={1} | ||
step={0.01} | ||
value={linearDamping} | ||
onChange={(e) => { | ||
physicsBody.setLinearDamping(e); | ||
}} | ||
/> | ||
{/* Angular Damping */} | ||
<FloatInputPropertyLine | ||
label="Angular Damping" | ||
min={0} | ||
max={1} | ||
step={0.01} | ||
value={angularDamping} | ||
onChange={(e) => { | ||
physicsBody.setAngularDamping(e); | ||
}} | ||
/> | ||
<Vector3PropertyLine label="Linear Velocity" value={linearVelocity} onChange={(value) => physicsBody.setLinearVelocity(value)} /> | ||
<Vector3PropertyLine label="Angular Velocity" value={angularVelocity} onChange={(value) => physicsBody.setAngularVelocity(value)} /> | ||
{/* Physics Mass Properties Controls */} | ||
{massProperties && ( | ||
<> | ||
<FloatInputPropertyLine | ||
label="Mass" | ||
value={massProperties.mass ?? 0} | ||
min={0} | ||
step={0.01} | ||
onChange={(value) => { | ||
physicsBody.setMassProperties({ ...massProperties, mass: value }); | ||
}} | ||
/> | ||
<Vector3PropertyLine | ||
label="Center of Mass" | ||
value={centerOfMass} | ||
onChange={(value) => { | ||
physicsBody.setMassProperties({ ...massProperties, centerOfMass: value }); | ||
}} | ||
/> | ||
<Vector3PropertyLine | ||
label="Inertia" | ||
value={inertia} | ||
onChange={(value) => { | ||
physicsBody.setMassProperties({ ...massProperties, inertia: value }); | ||
}} | ||
/> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/dev/inspector-v2/src/services/panes/properties/physicsPropertiesService.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { ServiceDefinition } from "../../../modularity/serviceDefinition"; | ||
import type { IPropertiesService } from "./propertiesService"; | ||
|
||
import { TransformNode } from "core/Meshes/transformNode"; | ||
|
||
import { PropertiesServiceIdentity } from "./propertiesService"; | ||
import { PhysicsBodyProperties } from "../../../components/properties/physicsProperties"; | ||
import { useProperty } from "../../../hooks/compoundPropertyHooks"; | ||
import { PlaceholderPropertyLine } from "shared-ui-components/fluent/hoc/propertyLine"; | ||
|
||
export const PhysicsPropertiesSectionIdentity = Symbol("Physics"); | ||
|
||
export const PhysicsPropertiesServiceDefinition: ServiceDefinition<[], [IPropertiesService]> = { | ||
friendlyName: "Physics Properties", | ||
consumes: [PropertiesServiceIdentity], | ||
factory: (propertiesService) => { | ||
const physicsSectionRegistration = propertiesService.addSection({ | ||
order: 5, | ||
identity: PhysicsPropertiesSectionIdentity, | ||
}); | ||
|
||
const contentRegistration = propertiesService.addSectionContent({ | ||
key: "Physics Properties", | ||
predicate: (entity: unknown) => entity instanceof TransformNode, | ||
content: [ | ||
// "Physics" section. | ||
{ | ||
section: PhysicsPropertiesSectionIdentity, | ||
order: 0, | ||
component: ({ context: node }) => { | ||
const physicsBody = useProperty(node, "physicsBody"); | ||
|
||
if (!physicsBody) { | ||
return <PlaceholderPropertyLine label="No Physics Body" value={undefined} onChange={() => {}} />; | ||
} | ||
|
||
return <PhysicsBodyProperties physicsBody={physicsBody} />; | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return { | ||
dispose: () => { | ||
contentRegistration.dispose(); | ||
physicsSectionRegistration.dispose(); | ||
}, | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.