1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
import {
Text,
Accordion,
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
Box,
Flex,
StackDivider,
Switch,
VStack,
} from '@chakra-ui/react'
import React, { useCallback } from 'react'
import { initialPhysics } from '../config'
import { EnableSection } from './EnableSection'
import { SliderWithInfo } from './SliderWithInfo'
export interface PhysicsPanelProps {
physics: typeof initialPhysics
setPhysics: any
}
export const PhysicsPanel = (props: PhysicsPanelProps) => {
const { physics, setPhysics } = props
const setPhysicsCallback = useCallback((val: number, phys: string, scale: number) => {
setPhysics((curr: typeof initialPhysics) => {
return { ...curr, [phys]: val / scale }
})
}, [])
return (
<Box>
<VStack
spacing={2}
justifyContent="flex-start"
divider={<StackDivider borderColor="gray.500" />}
align="stretch"
paddingLeft={7}
color="gray.800"
>
<EnableSection
label="Gravity"
value={physics.gravityOn}
onChange={() => setPhysics({ ...physics, gravityOn: !physics.gravityOn })}
>
<Flex justifyContent="space-between">
<Text>Also in local</Text>
<Switch
onChange={() => {
setPhysics((curr: typeof initialPhysics) => {
return { ...curr, gravityLocal: !curr.gravityLocal }
})
}}
isChecked={physics.gravityLocal}
></Switch>
</Flex>
<SliderWithInfo
label="Strength"
value={physics.gravity * 10}
onChange={(v: number) => setPhysicsCallback(v, 'gravity', 10)}
/>
</EnableSection>
<SliderWithInfo
value={-physics.charge / 100}
onChange={(v) => setPhysicsCallback(v, 'charge', -1 / 100)}
label="Repulsive Force"
/>
<EnableSection
label="Collision"
infoText="Perfomance sap, disable if slow"
value={physics.collision}
onChange={() => setPhysics({ ...physics, collision: !physics.collision })}
>
<SliderWithInfo
value={physics.collisionStrength / 5}
onChange={(v) => setPhysicsCallback(v, 'collisionStrength', 1 / 5)}
label="Collision Radius"
infoText="Easy with this one, high values can lead to a real jiggly mess"
/>
</EnableSection>
<SliderWithInfo
value={physics.linkStrength * 5}
onChange={(v) => setPhysicsCallback(v, 'linkStrength', 5)}
label="Link Force"
/>
<SliderWithInfo
label="Link Iterations"
value={physics.linkIts}
onChange={(v) => setPhysicsCallback(v, 'linkIts', 1)}
min={0}
max={6}
step={1}
infoText="How many links down the line the physics of a single node affects (Slow)"
/>
<SliderWithInfo
label="Viscosity"
value={physics.velocityDecay * 10}
onChange={(v) => setPhysicsCallback(v, 'velocityDecay', 10)}
/>
</VStack>
<Box>
<Accordion paddingLeft={3} allowToggle>
<AccordionItem>
<AccordionButton>
<Text>Advanced</Text>
<AccordionIcon marginRight={2} />
</AccordionButton>
<AccordionPanel>
<VStack
spacing={2}
justifyContent="flex-start"
divider={<StackDivider borderColor="gray.500" />}
align="stretch"
paddingLeft={3}
color="gray.800"
>
<SliderWithInfo
label="Stabilization rate"
value={physics.alphaDecay * 50}
onChange={(v) => setPhysicsCallback(v, 'alphaDecay', 50)}
/>
<EnableSection
label="Center nodes"
value={physics.centering}
onChange={() => setPhysics({ ...physics, centering: !physics.centering })}
infoText="Keeps the nodes in the center of the viewport. If disabled you can drag the nodes anywhere you want."
>
<SliderWithInfo
label="Centering Strength"
value={physics.centeringStrength}
max={2}
step={0.01}
onChange={(v) => setPhysicsCallback(v, 'centeringStrength', 1)}
/>
</EnableSection>
</VStack>
</AccordionPanel>
</AccordionItem>
</Accordion>
</Box>
</Box>
)
}
|