fix: invalidate frame on uniform change

This commit is contained in:
TrèsAbhi committed 2024-10-18 11:39:56 -05:00
1 parent 1f7b78dabc
commit 099e878c55
3 files changed
+23 -1

No files matched your search

@@ -4,7 +4,7 @@ import {
isExplosive,
resolvePenetrationCoefficient,
} from '@blitzkit/core';
import { useFrame } from '@react-three/fiber';
import { invalidate, useFrame } from '@react-three/fiber';
import { useEffect } from 'react';
import { MeshBasicMaterial, Object3D, ShaderMaterial, Vector2 } from 'three';
import { degToRad } from 'three/src/math/MathUtils.js';
@@ -74,12 +74,15 @@ export function PrimaryArmorSceneComponent({
const duel = duelStore.getState();
await handleProtagonistEquipmentChange(duel.protagonist.equipmentMatrix);
await handleAntagonistEquipmentChange(duel.antagonist.equipmentMatrix);
invalidate();
}
function handleGreenPenetrationChange(greenPenetration: boolean) {
material.uniforms.greenPenetration.value = greenPenetration;
invalidate();
}
function handleOpaqueChange(opaque: boolean) {
material.uniforms.opaque.value = opaque;
invalidate();
}
function handleWireframeChange(wireframe: boolean) {
material.wireframe = wireframe;
@@ -96,6 +99,8 @@ export function PrimaryArmorSceneComponent({
material.uniforms.thickness.value = hasEnhancedArmor
? thickness * 1.03
: thickness;
invalidate();
}
async function handleAntagonistEquipmentChange(equipment: EquipmentMatrix) {
const duel = duelStore.getState();
@@ -110,6 +115,8 @@ export function PrimaryArmorSceneComponent({
material.uniforms.penetration.value =
penetration *
resolvePenetrationCoefficient(hasCalibratedShells, shell.type);
invalidate();
}
handleShellChange(duelStore.getState().antagonist.shell);
@@ -156,6 +163,8 @@ export function PrimaryArmorSceneComponent({
spacedArmorRenderTarget.depthTexture;
material.uniforms.inverseProjectionMatrix.value =
camera.projectionMatrixInverse;
invalidate();
});
return (
@@ -2,6 +2,7 @@ import {
resolvePenetrationCoefficient,
type ShellDefinition,
} from '@blitzkit/core';
import { invalidate } from '@react-three/fiber';
import { useEffect } from 'react';
import {
AdditiveBlending,
@@ -51,6 +52,7 @@ export function SpacedArmorSubExternal({
useEffect(() => {
function handleShellChange(shell: ShellDefinition) {
material.uniforms.penetration.value = shell.penetration.near;
invalidate();
}
async function handleProtagonistEquipmentChange(
equipment: EquipmentMatrix,
@@ -64,6 +66,8 @@ export function SpacedArmorSubExternal({
material.uniforms.thickness.value = hasEnhancedArmor
? thickness * 1.03
: thickness;
invalidate();
}
async function handleAntagonistEquipmentChange(equipment: EquipmentMatrix) {
const duel = duelStore.getState();
@@ -78,6 +82,8 @@ export function SpacedArmorSubExternal({
material.uniforms.penetration.value =
penetration *
resolvePenetrationCoefficient(hasCalibratedShells, shell.type);
invalidate();
}
handleShellChange(duelStore.getState().antagonist.shell);
@@ -3,6 +3,7 @@ import {
resolvePenetrationCoefficient,
type ShellDefinition,
} from '@blitzkit/core';
import { invalidate } from '@react-three/fiber';
import { useEffect } from 'react';
import {
AdditiveBlending,
@@ -61,6 +62,8 @@ export function SpacedArmorSubSpaced({
material.uniforms.normalization.value = degToRad(
shell.normalization ?? 0,
);
invalidate();
}
async function handleProtagonistEquipmentChange(
equipment: EquipmentMatrix,
@@ -74,6 +77,8 @@ export function SpacedArmorSubSpaced({
material.uniforms.thickness.value = hasEnhancedArmor
? thickness * 1.03
: thickness;
invalidate();
}
async function handleAntagonistEquipmentChange(equipment: EquipmentMatrix) {
const duel = duelStore.getState();
@@ -88,6 +93,8 @@ export function SpacedArmorSubSpaced({
material.uniforms.penetration.value =
penetration *
resolvePenetrationCoefficient(hasCalibratedShells, shell.type);
invalidate();
}
handleShellChange(duelStore.getState().antagonist.shell);