mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: optimized state handling
This commit is contained in:
1 parent
033d361cea
commit
230b2df5fd
6 files changed
+145
-186
No files matched your search
@@ -1,33 +1,33 @@
|
||||
import { MeshProps } from '@react-three/fiber';
|
||||
import { MeshStandardMaterial } from 'three';
|
||||
import CustomShaderMaterial from 'three-custom-shader-material';
|
||||
import { degToRad } from 'three/src/math/MathUtils';
|
||||
import { canSplash } from '../../core/blitz/canSplash';
|
||||
import { isExplosive } from '../../core/blitz/isExplosive';
|
||||
import { resolveNearPenetration } from '../../core/blitz/resolveNearPenetration';
|
||||
import { useTankopedia } from '../../stores/tankopedia';
|
||||
import fragmentShader from './shaders/fragment.glsl';
|
||||
import vertexShader from './shaders/vertex.glsl';
|
||||
|
||||
interface ArmorMeshProps extends MeshProps {
|
||||
isExplosive: boolean;
|
||||
canSplash: boolean;
|
||||
isSpaced: boolean;
|
||||
isExternalModule?: boolean;
|
||||
thickness: number;
|
||||
penetration: number;
|
||||
caliber: number;
|
||||
ricochet: number;
|
||||
normalization: number;
|
||||
}
|
||||
|
||||
export function ArmorMesh({
|
||||
isExplosive,
|
||||
canSplash,
|
||||
isSpaced,
|
||||
isExternalModule = false,
|
||||
thickness,
|
||||
penetration,
|
||||
caliber,
|
||||
ricochet,
|
||||
normalization,
|
||||
...props
|
||||
}: ArmorMeshProps) {
|
||||
const shell = useTankopedia((state) => {
|
||||
if (!state.areTanksAssigned) return;
|
||||
return state.antagonist.shell;
|
||||
});
|
||||
|
||||
if (!shell) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{!isSpaced && (
|
||||
@@ -45,15 +45,19 @@ export function ArmorMesh({
|
||||
fragmentShader={fragmentShader}
|
||||
vertexShader={vertexShader}
|
||||
uniforms={{
|
||||
isExplosive: { value: isExplosive },
|
||||
canSplash: { value: canSplash },
|
||||
isExplosive: { value: isExplosive(shell.type) },
|
||||
canSplash: { value: canSplash(shell.type) },
|
||||
isSpaced: { value: isSpaced },
|
||||
isExternalModule: { value: isExternalModule },
|
||||
thickness: { value: thickness },
|
||||
penetration: { value: penetration },
|
||||
caliber: { value: caliber },
|
||||
ricochet: { value: ricochet * (Math.PI / 180) },
|
||||
normalization: { value: normalization * (Math.PI / 180) },
|
||||
penetration: {
|
||||
value: resolveNearPenetration(shell.penetration),
|
||||
},
|
||||
caliber: { value: shell.caliber },
|
||||
ricochet: { value: degToRad(shell.ricochet ?? 90) },
|
||||
normalization: {
|
||||
value: degToRad(shell.normalization ?? 0),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</mesh>
|
||||
|
||||
Reference in new issue
Block a user