Open
Conversation
tknkaa
reviewed
Feb 19, 2026
tknkaa
reviewed
Feb 19, 2026
Contributor
tknkaa
left a comment
There was a problem hiding this comment.
細かい点についてはレビューを見てほしいのですが、それとは別でシミュレーションゲームにするには衝突をシミュレートするためのボタンがあるといいかと思います。
| ))} | ||
| <Simulation planets={planets} setExplosions={setExplosions} /> | ||
| {explosions.map((exp, idx) => ( | ||
| <Explosion key={idx} planet={exp} /> |
| return ( | ||
| <group ref={groupRef}> | ||
| {fragments.map((f, i) => ( | ||
| <primitive key={i} object={f.mesh} /> |
Contributor
There was a problem hiding this comment.
別ファイルのレビューで指摘したように key に配列のインデックスを指定するのは一般的に React のアンチパターンとされています。ただ、この場合は追加削除がなさそうなので、バグの原因はならない可能性があります。
| } | ||
| interface SimulationProps { | ||
| planets: Planet[]; | ||
| setExplosions: React.Dispatch<React.SetStateAction<Planet[]>>; |
Contributor
There was a problem hiding this comment.
これもついやりがちなんですけど、基本的に状態管理は親コンポーネントでやりたいので、できれば setter を props で渡すのは避けてほしいです。今回なら、以下のような書き方ができます。
// 子
if (isColliding(a, b)) {
if (!collidedPairsRef.current.has(key)) {
collidedPairsRef.current.add(key)
onExplosion(a, b) // 「衝突した」という事実だけ伝える
}
}
// props の型
interface SimulationProps {
planets: Planet[]
onExplosion: (a: Planet, b: Planet) => void
}
// 親
<Simulation
planets={planets}
onExplosion={(a, b) => setExplosions(prev => [...prev, a, b])}
/>|
|
||
| setFragments((prev) => { | ||
| const alive: Fragment[] = []; | ||
| prev.forEach((f) => { |
Contributor
There was a problem hiding this comment.
別ファイルのレビューで指摘したように for 文に統一するのがいいと思います。
|
|
||
| type ExplosionProps = { | ||
| planet: Planet; | ||
| fragmentCount?: number; |
Contributor
There was a problem hiding this comment.
fragmentCount が undefined になる状況がよく分からなかったのですが、もし undefined になる状況がないなら ? は外すと後で undefined かどうかチェックをする必要がなくなるかと思います。
| fragmentCount = 50, | ||
| onComplete, | ||
| }: ExplosionProps) => { | ||
| const groupRef = useRef<THREE.Group>(null); |
Contributor
There was a problem hiding this comment.
これは型エラーになるかと思います。<THREE.Group | null> のように型を広げる必要がありそうです。
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
暫定的に衝突判定を実装
・とりあえず惑星2つを配列に入れて処理
・Simulation関数をいったん作り、内部で並進の処理と一緒に衝突判定を実施
・爆発のエフェクトを仮で実装