mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
Merge branch 'main' into data-driven
This commit is contained in:
34 files changed
+986
-992
No files matched your search
@@ -1,24 +1,18 @@
|
||||
import { isExplosive, resolvePenetrationCoefficient } from "@blitzkit/core";
|
||||
import { useEffect } from "react";
|
||||
import {
|
||||
AdditiveBlending,
|
||||
MeshBasicMaterial,
|
||||
ShaderMaterial,
|
||||
type Object3D,
|
||||
} from "three";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { AdditiveBlending, MeshBasicMaterial, ShaderMaterial } from "three";
|
||||
import { degToRad } from "three/src/math/MathUtils.js";
|
||||
import { jsxTree } from "../../core/blitzkit/jsxTree";
|
||||
import type { ArmorPlate } from "../../hooks/useArmorPlates";
|
||||
import { getDuelModules } from "../../hooks/useDuelModules";
|
||||
import { hasEquipment } from "../../hooks/useEquipment";
|
||||
import { usePlateItems } from "../../hooks/usePlateItems";
|
||||
import { Tankopedia } from "../../stores/tankopedia";
|
||||
import { ArmorType } from "../SpacedArmorScene";
|
||||
import type { ArmorUserData } from "../SpacedArmorSceneComponent";
|
||||
import { Batch } from "../Batch";
|
||||
import fragmentShader from "./shaders/fragment.glsl?raw";
|
||||
import vertexShader from "./shaders/vertex.glsl?raw";
|
||||
|
||||
interface SpacedArmorSubSpacedProps {
|
||||
node: Object3D;
|
||||
thickness: number;
|
||||
plates: ArmorPlate[];
|
||||
}
|
||||
|
||||
const depthWriteMaterial = new MeshBasicMaterial({
|
||||
@@ -26,26 +20,27 @@ const depthWriteMaterial = new MeshBasicMaterial({
|
||||
colorWrite: false,
|
||||
});
|
||||
|
||||
export function SpacedArmorSubSpaced({
|
||||
node,
|
||||
thickness,
|
||||
}: SpacedArmorSubSpacedProps) {
|
||||
const material = new ShaderMaterial({
|
||||
fragmentShader,
|
||||
vertexShader,
|
||||
export function SpacedArmorSubSpaced({ plates }: SpacedArmorSubSpacedProps) {
|
||||
const material = useMemo(
|
||||
() =>
|
||||
new ShaderMaterial({
|
||||
fragmentShader,
|
||||
vertexShader,
|
||||
|
||||
depthTest: true,
|
||||
depthWrite: false,
|
||||
blending: AdditiveBlending,
|
||||
depthTest: true,
|
||||
depthWrite: false,
|
||||
blending: AdditiveBlending,
|
||||
|
||||
uniforms: {
|
||||
thickness: { value: null },
|
||||
penetration: { value: null },
|
||||
caliber: { value: null },
|
||||
ricochet: { value: null },
|
||||
normalization: { value: null },
|
||||
},
|
||||
});
|
||||
uniforms: {
|
||||
thicknessCoefficient: { value: null },
|
||||
penetration: { value: null },
|
||||
caliber: { value: null },
|
||||
ricochet: { value: null },
|
||||
normalization: { value: null },
|
||||
},
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
function handleShellChange() {
|
||||
@@ -75,8 +70,8 @@ export function SpacedArmorSubSpaced({
|
||||
? protagonist.equalizer?.armor
|
||||
: undefined) ?? 1;
|
||||
|
||||
material.uniforms.thickness.value =
|
||||
thickness * (hasEnhancedArmor ? 1.04 : 1) * equalizer;
|
||||
material.uniforms.thicknessCoefficient.value =
|
||||
(hasEnhancedArmor ? 1.04 : 1) * equalizer;
|
||||
}
|
||||
function handleAntagonistEquipmentChange() {
|
||||
const antagonist = getDuelModules("antagonist").tank;
|
||||
@@ -133,50 +128,15 @@ export function SpacedArmorSubSpaced({
|
||||
return () => {
|
||||
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||
};
|
||||
});
|
||||
}, [material]);
|
||||
|
||||
|
||||
const items = usePlateItems(plates);
|
||||
|
||||
return (
|
||||
<>
|
||||
{jsxTree(node, {
|
||||
group(_, props, key) {
|
||||
return <group {...props} key={`${key}-spaced-sub-spaced-exclude`} />;
|
||||
},
|
||||
|
||||
mesh(_, props, key) {
|
||||
return (
|
||||
<mesh
|
||||
{...props}
|
||||
key={`${key}-spaced-sub-spaced-exclude`}
|
||||
renderOrder={2}
|
||||
material={material}
|
||||
onClick={() => {}}
|
||||
userData={
|
||||
{
|
||||
type: ArmorType.Spaced,
|
||||
thickness,
|
||||
} satisfies ArmorUserData
|
||||
}
|
||||
/>
|
||||
);
|
||||
},
|
||||
})}
|
||||
|
||||
{jsxTree(node, {
|
||||
group(_, props, key) {
|
||||
return <group {...props} key={`${key}-spaced-sub-spaced-include`} />;
|
||||
},
|
||||
|
||||
mesh(_, props, key) {
|
||||
return (
|
||||
<mesh
|
||||
{...props}
|
||||
key={`${key}-spaced-sub-spaced-include`}
|
||||
renderOrder={5}
|
||||
material={depthWriteMaterial}
|
||||
/>
|
||||
);
|
||||
},
|
||||
})}
|
||||
<Batch items={items} material={material} renderOrder={2} />
|
||||
<Batch items={items} material={depthWriteMaterial} renderOrder={5} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -3,13 +3,15 @@ precision mediump float;
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vViewPosition;
|
||||
|
||||
uniform float thickness;
|
||||
uniform float thicknessCoefficient;
|
||||
varying float vThickness;
|
||||
uniform float penetration;
|
||||
uniform float caliber;
|
||||
uniform float ricochet;
|
||||
uniform float normalization;
|
||||
|
||||
void main() {
|
||||
float thickness = vThickness * thicknessCoefficient;
|
||||
float angle = acos(dot(vNormal, -vViewPosition) / length(vViewPosition));
|
||||
|
||||
bool threeCalibersRule = caliber > thickness * 3.0;
|
||||
|
||||
@@ -2,12 +2,31 @@ precision mediump float;
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vViewPosition;
|
||||
varying float vThickness;
|
||||
|
||||
#include <batching_pars_vertex>
|
||||
|
||||
void main() {
|
||||
vec4 vViewPosition4 = modelViewMatrix * vec4(position, 1.0);
|
||||
vec4 localPosition = vec4(position, 1.0);
|
||||
vec3 localNormal = normal;
|
||||
|
||||
#ifdef USE_BATCHING
|
||||
#include <batching_vertex>
|
||||
|
||||
localPosition = batchingMatrix * localPosition;
|
||||
localNormal = normalize(mat3(batchingMatrix) * localNormal);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BATCHING_COLOR
|
||||
vThickness = getBatchingColor(getIndirectIndex(gl_DrawID)).r;
|
||||
#else
|
||||
vThickness = 0.0;
|
||||
#endif
|
||||
|
||||
vec4 vViewPosition4 = modelViewMatrix * localPosition;
|
||||
|
||||
vViewPosition = vViewPosition4.xyz;
|
||||
vNormal = normalMatrix * normal;
|
||||
vNormal = normalMatrix * localNormal;
|
||||
|
||||
gl_Position = projectionMatrix * vViewPosition4;
|
||||
}
|
||||
Reference in new issue
Block a user