Skip to content

Commit 94219a4

Browse files
MarkMark
Mark
authored and
Mark
committed
Reformatting indent to 4 spaces
1 parent ee027e1 commit 94219a4

File tree

7 files changed

+1475
-1471
lines changed

7 files changed

+1475
-1471
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4

src/animationComponents/Scopes/CompoundEntity.js

+1,088-1,088
Large diffs are not rendered by default.

src/animationComponents/Scopes/CompoundEntityGroup.js

+54-54
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,62 @@ import React, { forwardRef, useRef, useImperativeHandle } from 'react';
22
import * as THREE from 'three';
33

44
const CompoundEntityGroup = forwardRef(({ children, position, userData }, ref) => {
5-
const internalRef = useRef();
6-
const impulseRef = useRef(new THREE.Vector3());
7-
const centerRef = useRef();
5+
const internalRef = useRef();
6+
const impulseRef = useRef(new THREE.Vector3());
7+
const centerRef = useRef();
88

9-
useImperativeHandle(ref, () => ({
10-
get current() {
11-
return internalRef.current;
12-
},
13-
setImpulse: (newImpulse) => {
14-
impulseRef.current.copy(newImpulse);
15-
},
16-
getImpulse: () => {
17-
return impulseRef.current.clone();
18-
},
19-
addImpulse: (newImpulse) => {
20-
impulseRef.current.add(newImpulse);
21-
},
22-
getCenter: () => {
23-
if (centerRef.current) {
24-
return centerRef.current.clone();
25-
} else {
26-
return null;
27-
}
28-
},
29-
setCenter: (center) => {
30-
if (!centerRef.current) {
31-
centerRef.current = new THREE.Vector3()
32-
}
33-
return centerRef.current.copy(center);
34-
},
35-
worldToLocal: (vector) => {
36-
return internalRef.current.worldToLocal(vector);
37-
},
38-
localToWorld: (vector) => {
39-
return internalRef.current.localToWorld(vector);
40-
},
41-
getWorldPosition: (vector) => {
42-
return internalRef.current.getWorldPosition(vector);
43-
},
44-
getUserData: () => {
45-
if (internalRef.current) {
46-
return internalRef.current.userData;
47-
} else {
48-
return null;
49-
}
50-
},
51-
setUserData: (userData) => {
52-
internalRef.current.userData = userData;
53-
},
54-
}), [internalRef]);
9+
useImperativeHandle(ref, () => ({
10+
get current() {
11+
return internalRef.current;
12+
},
13+
setImpulse: (newImpulse) => {
14+
impulseRef.current.copy(newImpulse);
15+
},
16+
getImpulse: () => {
17+
return impulseRef.current.clone();
18+
},
19+
addImpulse: (newImpulse) => {
20+
impulseRef.current.add(newImpulse);
21+
},
22+
getCenter: () => {
23+
if (centerRef.current) {
24+
return centerRef.current.clone();
25+
} else {
26+
return null;
27+
}
28+
},
29+
setCenter: (center) => {
30+
if (!centerRef.current) {
31+
centerRef.current = new THREE.Vector3()
32+
}
33+
return centerRef.current.copy(center);
34+
},
35+
worldToLocal: (vector) => {
36+
return internalRef.current.worldToLocal(vector);
37+
},
38+
localToWorld: (vector) => {
39+
return internalRef.current.localToWorld(vector);
40+
},
41+
getWorldPosition: (vector) => {
42+
return internalRef.current.getWorldPosition(vector);
43+
},
44+
getUserData: () => {
45+
if (internalRef.current) {
46+
return internalRef.current.userData;
47+
} else {
48+
return null;
49+
}
50+
},
51+
setUserData: (userData) => {
52+
internalRef.current.userData = userData;
53+
},
54+
}), [internalRef]);
5555

56-
return (
57-
<group ref={internalRef} position={position} userData={userData}>
58-
{children}
59-
</group>
60-
);
56+
return (
57+
<group ref={internalRef} position={position} userData={userData}>
58+
{children}
59+
</group>
60+
);
6161
});
6262

6363
export default CompoundEntityGroup;

src/animationComponents/Scopes/Particle.js

+93-93
Original file line numberDiff line numberDiff line change
@@ -5,124 +5,124 @@ import ParticleRigidBody from './ParticleRigidBody';
55
import { BallCollider } from '@react-three/rapier';
66
import _ from 'lodash';
77
import { getColor } from './utils.js';
8-
9-
// The Particle uses ParticleRigidBody which extends RigidBody to allow for impulses to be accumulated before being applied
10-
const Particle = React.memo(React.forwardRef(({ id, index, indexArray, scope, initialPosition, radius, config, ...props }, ref) => {
11-
8+
9+
// The Particle uses ParticleRigidBody which extends RigidBody to allow for impulses to be accumulated before being applied
10+
const Particle = React.memo(React.forwardRef(({ id, index, indexArray, scope, initialPosition, radius, config, ...props }, ref) => {
11+
1212
const internalRef = useRef(); // because we forwardRef and want to use the ref locally too
1313
useImperativeHandle(ref, () => internalRef.current);
14-
14+
1515
const isDebug = props.debug || config.debug;
1616
const color = useMemo(() => getColor(config, scope, props.color || "blue"));
1717
const [colliderRadius, setColliderRadius] = useState(radius);
1818
const registeredRef = useRef(false);
1919
const [initialize, setInitialize] = useState(true);
20-
20+
2121
// Calculate the unique global index for the Particle
2222
const calculateUniqueIndex = (indexArray, entityCounts) => {
23-
let multiplier = 1;
24-
let uniqueIndex = 0;
25-
for (let i = indexArray.length - 1; i >= 0; i--) {
26-
uniqueIndex += indexArray[i] * multiplier;
27-
multiplier *= entityCounts[i];
28-
}
29-
return uniqueIndex;
23+
let multiplier = 1;
24+
let uniqueIndex = 0;
25+
for (let i = indexArray.length - 1; i >= 0; i--) {
26+
uniqueIndex += indexArray[i] * multiplier;
27+
multiplier *= entityCounts[i];
28+
}
29+
return uniqueIndex;
3030
};
31-
31+
3232
// With adding/removing Particles this may not be unique - use a singleton to get a unique id
3333
const uniqueIndex = useMemo(() => calculateUniqueIndex(indexArray, config.entityCounts), [indexArray, config.entityCounts]);
34-
34+
3535
// When scaling a Particle we need to modify the joint positions
3636
useFrame(() => {
37-
if (internalRef.current) {
38-
if (internalRef.current.applyImpulses) {
39-
internalRef.current.applyImpulses();
40-
}
41-
//
42-
const userData = internalRef.current.getUserData();
43-
// Could adjust scale over multiple frames
44-
if (userData?.scale !== userData?.rigidScale) {
45-
let relativeScale = userData.scale;
46-
if (userData.rigidScale) {
47-
relativeScale = userData.scale / userData.rigidScale;
48-
}
49-
const newRadius = relativeScale * colliderRadius
50-
setColliderRadius(newRadius);
51-
internalRef.current.setUserData(userData)
52-
props.particleJointsRef.current[uniqueIndex].forEach((jointIndex) => {
53-
const joint = props.jointRefsRef.current[jointIndex].current;
54-
if (joint.body1().userData.uniqueIndex == uniqueIndex) {
55-
const a1 = joint.anchor1();
56-
joint.setAnchor1({
57-
x: a1.x * relativeScale,
58-
y: a1.y * relativeScale,
59-
z: a1.z * relativeScale,
60-
})
37+
if (internalRef.current) {
38+
if (internalRef.current.applyImpulses) {
39+
internalRef.current.applyImpulses();
6140
}
62-
if (joint.body2().userData.uniqueIndex == uniqueIndex) {
63-
const a2 = joint.anchor2();
64-
joint.setAnchor2({
65-
x: a2.x * relativeScale,
66-
y: a2.y * relativeScale,
67-
z: a2.z * relativeScale,
68-
})
41+
//
42+
const userData = internalRef.current.getUserData();
43+
// Could adjust scale over multiple frames
44+
if (userData?.scale !== userData?.rigidScale) {
45+
let relativeScale = userData.scale;
46+
if (userData.rigidScale) {
47+
relativeScale = userData.scale / userData.rigidScale;
48+
}
49+
const newRadius = relativeScale * colliderRadius
50+
setColliderRadius(newRadius);
51+
internalRef.current.setUserData(userData)
52+
props.particleJointsRef.current[uniqueIndex].forEach((jointIndex) => {
53+
const joint = props.jointRefsRef.current[jointIndex].current;
54+
if (joint.body1().userData.uniqueIndex == uniqueIndex) {
55+
const a1 = joint.anchor1();
56+
joint.setAnchor1({
57+
x: a1.x * relativeScale,
58+
y: a1.y * relativeScale,
59+
z: a1.z * relativeScale,
60+
})
61+
}
62+
if (joint.body2().userData.uniqueIndex == uniqueIndex) {
63+
const a2 = joint.anchor2();
64+
joint.setAnchor2({
65+
x: a2.x * relativeScale,
66+
y: a2.y * relativeScale,
67+
z: a2.z * relativeScale,
68+
})
69+
}
70+
})
71+
userData.rigidScale = userData.scale;
72+
internalRef.current.setUserData(userData);
6973
}
70-
})
71-
userData.rigidScale = userData.scale;
72-
internalRef.current.setUserData(userData);
7374
}
74-
}
7575
});
76-
76+
7777
useEffect(() => {
78-
// Don't need registeredRef as sensitive to internalRef
79-
if (props.registerParticlesFn && internalRef.current && !registeredRef.current) {
80-
props.registerParticlesFn(index, [internalRef.current], radius);
81-
registeredRef.current = true;
82-
}
78+
// Don't need registeredRef as sensitive to internalRef
79+
if (props.registerParticlesFn && internalRef.current && !registeredRef.current) {
80+
props.registerParticlesFn(index, [internalRef.current], radius);
81+
registeredRef.current = true;
82+
}
8383
}, [props.registerParticlesFn, internalRef]);
84-
84+
8585
// Set the initial userData, don't do this in JSX (it would overwrite on renders)
8686
useEffect(() => {
87-
if (initialize && internalRef.current) {
88-
internalRef.current.setUserData({color: color, uniqueIndex: uniqueIndex});
89-
setInitialize(false);
90-
}
87+
if (initialize && internalRef.current) {
88+
internalRef.current.setUserData({ color: color, uniqueIndex: uniqueIndex });
89+
setInitialize(false);
90+
}
9191
}, [internalRef]);
92-
92+
9393
return (
94-
<>
95-
<ParticleRigidBody
96-
ref={internalRef}
97-
position={initialPosition}
98-
type="dynamic"
99-
colliders={false}
100-
linearDamping={0.5}
101-
angularDamping={0.5}
102-
enabledTranslations={[true, true, false]}
103-
enabledRotations={[false, false, true]}
104-
restitution={config.particleRestitution}
105-
ccd={config.ccd}
106-
>
107-
<BallCollider args={[colliderRadius]} />
108-
</ParticleRigidBody>
109-
{isDebug && (
11094
<>
111-
<Text
112-
position={[initialPosition[0], initialPosition[1], 0.1]} // Slightly offset in the z-axis to avoid z-fighting
113-
fontSize={radius / 2}
114-
color="black"
115-
anchorX="center"
116-
anchorY="middle"
117-
>
118-
{uniqueIndex}
119-
</Text>
95+
<ParticleRigidBody
96+
ref={internalRef}
97+
position={initialPosition}
98+
type="dynamic"
99+
colliders={false}
100+
linearDamping={0.5}
101+
angularDamping={0.5}
102+
enabledTranslations={[true, true, false]}
103+
enabledRotations={[false, false, true]}
104+
restitution={config.particleRestitution}
105+
ccd={config.ccd}
106+
>
107+
<BallCollider args={[colliderRadius]} />
108+
</ParticleRigidBody>
109+
{isDebug && (
110+
<>
111+
<Text
112+
position={[initialPosition[0], initialPosition[1], 0.1]} // Slightly offset in the z-axis to avoid z-fighting
113+
fontSize={radius / 2}
114+
color="black"
115+
anchorX="center"
116+
anchorY="middle"
117+
>
118+
{uniqueIndex}
119+
</Text>
120+
</>
121+
)}
120122
</>
121-
)}
122-
</>
123123
);
124-
}));
125-
126-
Particle.displayName = 'Particle'; // the name property doesn't exist because it uses forwardRef
124+
}));
125+
126+
Particle.displayName = 'Particle'; // the name property doesn't exist because it uses forwardRef
127127

128-
export default Particle;
128+
export default Particle;

0 commit comments

Comments
 (0)