feat: wireframe armor viewer

This commit is contained in:
TrèsAbhi committed 2024-02-18 16:56:52 -06:00
1 parent 544eb92a6b
commit 70f7b862e3
5 files changed
+34 -2

No files matched your search

+1
View File
@@ -130,6 +130,7 @@
"wargaming", "wargaming",
"webp", "webp",
"winrate", "winrate",
"wireframe",
"wotblitz", "wotblitz",
"xffn", "xffn",
"xkdkw", "xkdkw",
@@ -27,6 +27,9 @@ export function Options({ isFullScreen, canvas }: OptionsProps) {
const greenPenetration = useTankopediaPersistent( const greenPenetration = useTankopediaPersistent(
(state) => state.model.visual.greenPenetration, (state) => state.model.visual.greenPenetration,
); );
const wireframe = useTankopediaPersistent(
(state) => state.model.visual.wireframe,
);
const fullScreenAvailable = const fullScreenAvailable =
typeof document !== 'undefined' && document.fullscreenEnabled; typeof document !== 'undefined' && document.fullscreenEnabled;
const environment = useTankopediaPersistent( const environment = useTankopediaPersistent(
@@ -126,6 +129,17 @@ export function Options({ isFullScreen, canvas }: OptionsProps) {
</DropdownMenu.RadioGroup> </DropdownMenu.RadioGroup>
</DropdownMenu.SubContent> </DropdownMenu.SubContent>
</DropdownMenu.Sub> </DropdownMenu.Sub>
<DropdownMenu.CheckboxItem
checked={wireframe}
onCheckedChange={(checked) => {
mutateTankopediaPersistent((draft) => {
draft.model.visual.wireframe = checked;
});
}}
>
Wireframe
</DropdownMenu.CheckboxItem>
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu.Root> </DropdownMenu.Root>
@@ -57,6 +57,7 @@ export function ArmorMesh({
const scene = useThree((state) => state.scene); const scene = useThree((state) => state.scene);
const hasCalibratedShells = useAwait(hasEquipment(103)); const hasCalibratedShells = useAwait(hasEquipment(103));
const hasEnhancedArmor = useAwait(hasEquipment(110)); const hasEnhancedArmor = useAwait(hasEquipment(110));
const wireframe = initialTankopedia.model.visual.wireframe;
useEffect(() => { useEffect(() => {
async function updateQuickEquipments() { async function updateQuickEquipments() {
@@ -109,6 +110,15 @@ export function ArmorMesh({
} }
}, },
), ),
useTankopediaPersistent.subscribe(
(state) => state.model.visual.wireframe,
(wireframe) => {
if (material.current) {
material.current.wireframe = wireframe;
material.current.uniforms.wireframe.value = wireframe;
}
},
),
]; ];
return () => { return () => {
@@ -386,7 +396,9 @@ export function ArmorMesh({
}); });
}} }}
> >
{true && (
<shaderMaterial <shaderMaterial
wireframe={wireframe}
ref={material} ref={material}
fragmentShader={fragmentShader} fragmentShader={fragmentShader}
vertexShader={vertexShader} vertexShader={vertexShader}
@@ -422,8 +434,10 @@ export function ArmorMesh({
}, },
damage: { value: initialShell.damage.armor }, damage: { value: initialShell.damage.armor },
explosionRadius: { value: initialShell.explosionRadius ?? 0 }, explosionRadius: { value: initialShell.explosionRadius ?? 0 },
wireframe: { value: wireframe },
}} }}
/> />
)}
</mesh> </mesh>
</> </>
); );
@@ -19,6 +19,7 @@ uniform float maxThickness;
uniform bool greenPenetration; uniform bool greenPenetration;
uniform float damage; uniform float damage;
uniform float explosionRadius; uniform float explosionRadius;
uniform bool wireframe;
float depthToDistance(float depth) { float depthToDistance(float depth) {
mat4 projectionMatrixInverse = inverse(vProjectionMatrix); mat4 projectionMatrixInverse = inverse(vProjectionMatrix);
@@ -107,8 +108,8 @@ void main() {
} }
vec3 color = vec3(1.0, splashChance * 0.392, 0.0); vec3 color = vec3(1.0, splashChance * 0.392, 0.0);
if (greenPenetration) { if (greenPenetration || wireframe) {
gl_FragColor = vec4(mix(color, vec3(0.0, 1.0, 0.0), penetrationChance), 0.5); gl_FragColor = vec4(mix(color, vec3(0.0, 1.0, 0.0), penetrationChance), wireframe ? 1.0 : 0.5);
} else { } else {
gl_FragColor = vec4(color, (1.0 - penetrationChance) * 0.5); gl_FragColor = vec4(color, (1.0 - penetrationChance) * 0.5);
} }
+2
View File
@@ -30,6 +30,7 @@ export interface DuelMember {
interface TankopediaPersistent { interface TankopediaPersistent {
model: { model: {
visual: { visual: {
wireframe: boolean;
environment: (typeof ENVIRONMENTS)[number]; environment: (typeof ENVIRONMENTS)[number];
controlsEnabled: boolean; controlsEnabled: boolean;
showGrid: boolean; showGrid: boolean;
@@ -131,6 +132,7 @@ export const useTankopediaPersistent = create<TankopediaPersistent>()(
subscribeWithSelector<TankopediaPersistent>(() => ({ subscribeWithSelector<TankopediaPersistent>(() => ({
model: { model: {
visual: { visual: {
wireframe: false,
environment: ENVIRONMENTS[0], environment: ENVIRONMENTS[0],
controlsEnabled: true, controlsEnabled: true,
showGrid: true, showGrid: true,