mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-17 19:04:15 +01:00
Compare commits
5
Commits
8ff26d57f6
...
cde6904513
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cde6904513 | ||
|
|
997d1df8f9 | ||
|
|
9f15ded0c9 | ||
|
|
b2ee97b3d4 | ||
|
|
03d819a6c1 |
No files matched your search
Vendored
+1
@@ -222,6 +222,7 @@
|
||||
"yolo",
|
||||
"youtuber",
|
||||
"youtubers",
|
||||
"zoomable",
|
||||
"zustand"
|
||||
],
|
||||
"deno.enable": false,
|
||||
|
||||
@@ -917,6 +917,7 @@
|
||||
|
||||
"flexibility": {
|
||||
"yaw": "Yaw",
|
||||
"pitch": "Pitch",
|
||||
"depression": "Depression",
|
||||
"elevation": "Elevation"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Canvas } from '@react-three/fiber';
|
||||
import { GuessEphemeral } from '../stores/guessEphemeral';
|
||||
import { TankopediaDisplay } from '../stores/tankopediaPersistent/constants';
|
||||
import { SmartCanvas } from './SmartCanvas';
|
||||
import { Controls } from './Tankopedia/HeroSection/components/TankSandbox/components/Control';
|
||||
import { Lighting } from './Tankopedia/HeroSection/components/TankSandbox/components/Lighting';
|
||||
import { TankModel } from './Tankopedia/HeroSection/components/TankSandbox/components/TankModel';
|
||||
@@ -13,7 +13,7 @@ export function GuessRenderer() {
|
||||
const isRevealed = guessState !== null;
|
||||
|
||||
return (
|
||||
<Canvas
|
||||
<SmartCanvas
|
||||
style={{
|
||||
filter: `grayscale(${isRevealed ? 0 : 1}) contrast(${isRevealed ? 1 : CONTRAST}) brightness(${isRevealed ? 1 : BRIGHTNESS})`,
|
||||
// filter: `drop-shadow(0 0 1rem ${Var('black-a11')})`,
|
||||
@@ -25,6 +25,6 @@ export function GuessRenderer() {
|
||||
<Controls distanceScale={2} zoomable={false} />
|
||||
<Lighting display={TankopediaDisplay.Model} />
|
||||
<TankModel />
|
||||
</Canvas>
|
||||
</SmartCanvas>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Canvas, type CanvasProps } from '@react-three/fiber';
|
||||
import { forwardRef, useImperativeHandle, useRef } from 'react';
|
||||
import { useOnScreen } from '../hooks/useOnScreen';
|
||||
|
||||
export const SmartCanvas = forwardRef<HTMLCanvasElement, CanvasProps>(
|
||||
(props, ref) => {
|
||||
const canvas = useRef<HTMLCanvasElement>(null);
|
||||
const onScreen = useOnScreen(canvas);
|
||||
|
||||
useImperativeHandle(ref, () => canvas.current!, []);
|
||||
|
||||
return (
|
||||
<Canvas
|
||||
frameloop={onScreen ? 'demand' : 'never'}
|
||||
ref={canvas}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { useFrame } from '@react-three/fiber';
|
||||
|
||||
export const zoom = 60;
|
||||
|
||||
export function CameraPositioner() {
|
||||
useFrame(({ camera, gl: { domElement } }) => {
|
||||
const { width } = domElement.getBoundingClientRect();
|
||||
const physicalWidth = width / zoom;
|
||||
|
||||
camera.position.set(10, 0, -physicalWidth / 6);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
-3
@@ -1,4 +1,3 @@
|
||||
import { invalidate } from '@react-three/fiber';
|
||||
import type { QuicklimeEvent } from 'quicklime';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { Group } from 'three';
|
||||
@@ -19,8 +18,6 @@ export function CanvasContent() {
|
||||
if (!gun.current) return;
|
||||
|
||||
gun.current.rotation.x = event.data.pitch;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
modelTransformEvent.on(handleModelTransformEvent);
|
||||
|
||||
+5
-13
@@ -1,20 +1,12 @@
|
||||
import { Canvas } from '@react-three/fiber';
|
||||
import { SmartCanvas } from '../../../../../../../SmartCanvas';
|
||||
import { CameraPositioner, zoom } from './CameraPositioner';
|
||||
import { CanvasContent } from './CanvasContent';
|
||||
|
||||
export const zoom = 60;
|
||||
|
||||
export function FlexibilityCanvas() {
|
||||
return (
|
||||
<Canvas
|
||||
// frameloop="demand"
|
||||
orthographic
|
||||
camera={{
|
||||
zoom,
|
||||
position: [10, 0, -2],
|
||||
rotation: [0, Math.PI / 2, 0],
|
||||
}}
|
||||
>
|
||||
<SmartCanvas orthographic camera={{ zoom, rotation: [0, Math.PI / 2, 0] }}>
|
||||
<CanvasContent />
|
||||
</Canvas>
|
||||
<CameraPositioner />
|
||||
</SmartCanvas>
|
||||
);
|
||||
}
|
||||
+46
-7
@@ -1,7 +1,7 @@
|
||||
import { literals } from '@blitzkit/i18n';
|
||||
import { Box } from '@radix-ui/themes';
|
||||
import { useRef, useState } from 'react';
|
||||
import { radToDeg } from 'three/src/math/MathUtils.js';
|
||||
import { clamp, degToRad, radToDeg } from 'three/src/math/MathUtils.js';
|
||||
import { awaitableModelDefinitions } from '../../../../../../../../core/awaitables/modelDefinitions';
|
||||
import {
|
||||
DEFAULT_PITCH_TRANSITION,
|
||||
@@ -20,7 +20,11 @@ const ANGLE_COEFFICIENT = 1 / 10;
|
||||
const modelDefinition = await awaitableModelDefinitions;
|
||||
|
||||
function mag(x: number) {
|
||||
return ((2 / Math.PI) * Math.atan(ANGLE_COEFFICIENT * x) + 1) / 2;
|
||||
return (1 / Math.PI) * Math.atan(ANGLE_COEFFICIENT * x) + 1 / 2;
|
||||
}
|
||||
|
||||
function magInverse(y: number): number {
|
||||
return (1 / ANGLE_COEFFICIENT) * Math.tan(Math.PI * y - Math.PI / 2);
|
||||
}
|
||||
|
||||
function c(thetaDeg: number, m = 1) {
|
||||
@@ -32,6 +36,7 @@ export function FlexibilityCard() {
|
||||
const { strings } = useLocale();
|
||||
|
||||
const [yaw, setYaw] = useState(0);
|
||||
const [pitch, setPitch] = useState(0);
|
||||
const [minPitch, setMinPitch] = useState(0);
|
||||
const [maxPitch, setMaxPitch] = useState(0);
|
||||
|
||||
@@ -59,7 +64,8 @@ export function FlexibilityCard() {
|
||||
// right
|
||||
const mo = mag(p.max);
|
||||
if (y) {
|
||||
d += `M ${c(90 - y.max, mo)}`;
|
||||
d += `M 0 0`;
|
||||
d += `L ${c(90 - y.max, mo)}`;
|
||||
} else if (b) {
|
||||
d += `M ${c(-90 + b.range / 2 + t, mo)}`;
|
||||
} else {
|
||||
@@ -104,7 +110,8 @@ export function FlexibilityCard() {
|
||||
// right
|
||||
const mi = mag(p.min);
|
||||
if (y) {
|
||||
d += `M ${c(90 - y.max, mi)}`;
|
||||
d += `M 0 0`;
|
||||
d += `L ${c(90 - y.max, mi)}`;
|
||||
} else if (b) {
|
||||
d += `M ${c(-90 + b.range / 2 + t, mi)}`;
|
||||
} else {
|
||||
@@ -146,6 +153,10 @@ export function FlexibilityCard() {
|
||||
|
||||
d += `Z`;
|
||||
|
||||
const r = mag(radToDeg(-pitch));
|
||||
const dotX = r * Math.sin(yaw);
|
||||
const dotY = r * Math.cos(yaw);
|
||||
|
||||
return (
|
||||
<VisualizerCard
|
||||
ref={container}
|
||||
@@ -191,8 +202,12 @@ export function FlexibilityCard() {
|
||||
);
|
||||
|
||||
yaw = min[1];
|
||||
const pitch = min[0];
|
||||
let t = 2 * Math.sqrt((u / rect.width) ** 2 + (v / rect.height) ** 2);
|
||||
t = clamp(t, 0, 1);
|
||||
let pitch = degToRad(magInverse(-t));
|
||||
pitch = clamp(pitch, min[0], max[0]);
|
||||
|
||||
setPitch(pitch);
|
||||
setYaw(yaw);
|
||||
setMinPitch(min[0]);
|
||||
setMaxPitch(max[0]);
|
||||
@@ -248,7 +263,12 @@ export function FlexibilityCard() {
|
||||
strokeWidth="1px"
|
||||
strokeDasharray="0.5rem 0.5rem"
|
||||
vectorEffect="non-scaling-stroke"
|
||||
d="M 0.5 0 A 0.5 0.5 0 1 1 -0.5 0 A 0.5 0.5 0 1 1 0.5 0 Z"
|
||||
d={`
|
||||
M 0.5 0
|
||||
A 0.5 0.5 0 1 1 -0.5 0
|
||||
A 0.5 0.5 0 1 1 0.5 0
|
||||
Z
|
||||
`}
|
||||
/>
|
||||
</svg>
|
||||
|
||||
@@ -274,6 +294,19 @@ export function FlexibilityCard() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box
|
||||
position="absolute"
|
||||
left={`${50 * (dotX + 1)}%`}
|
||||
bottom={`${50 * (dotY + 1)}%`}
|
||||
width="0.25rem"
|
||||
height="0.25rem"
|
||||
style={{
|
||||
borderRadius: '50%',
|
||||
backgroundColor: Var('gray-12'),
|
||||
transform: 'translate(-50%, 50%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
<VisualizerCornerStat
|
||||
label={
|
||||
strings.website.tools.tankopedia.visualizers.flexibility.elevation
|
||||
@@ -294,10 +327,16 @@ export function FlexibilityCard() {
|
||||
side="top-right"
|
||||
/>
|
||||
|
||||
<VisualizerCornerStat
|
||||
label={strings.website.tools.tankopedia.visualizers.flexibility.pitch}
|
||||
value={literals(strings.common.units.deg, [radToDeg(pitch).toFixed(0)])}
|
||||
side="bottom-left"
|
||||
/>
|
||||
|
||||
<VisualizerCornerStat
|
||||
label={strings.website.tools.tankopedia.visualizers.flexibility.yaw}
|
||||
value={literals(strings.common.units.deg, [radToDeg(yaw).toFixed(0)])}
|
||||
side="bottom-left"
|
||||
side="bottom-right"
|
||||
/>
|
||||
</VisualizerCard>
|
||||
);
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ export function ModelChunk({ onlyGun = false }: Props) {
|
||||
<>
|
||||
<mesh key={key} {...props} material={surfaceMaterial} />
|
||||
<lineSegments material={outlineMaterial}>
|
||||
<edgesGeometry args={[mesh.geometry, 30]} />
|
||||
<edgesGeometry args={[mesh.geometry, 29]} />
|
||||
</lineSegments>
|
||||
</>
|
||||
);
|
||||
|
||||
+9
-1
@@ -1,4 +1,5 @@
|
||||
import { Box, Card, Flex } from '@radix-ui/themes';
|
||||
import { Var } from '../../../../../../../core/radix/var';
|
||||
import type { MaybeSkeletonComponentProps } from '../../../../../../../types/maybeSkeletonComponentProps';
|
||||
import { FlexibilityCanvas } from './components/FlexibilityCanvas';
|
||||
import { FlexibilityCard } from './components/FlexibilityCard';
|
||||
@@ -10,7 +11,14 @@ export function GunFlexibilityVisualizer({
|
||||
<Flex direction="column-reverse" gap="0">
|
||||
<Box mt="-4" px="2">
|
||||
<Card variant="classic" style={{ height: '10rem' }}>
|
||||
<Box position="absolute" width="100%" height="100%" top="0" left="0">
|
||||
<Box
|
||||
style={{ backgroundColor: Var('gray-1') }}
|
||||
position="absolute"
|
||||
width="100%"
|
||||
height="100%"
|
||||
top="0"
|
||||
left="0"
|
||||
>
|
||||
{!skeleton && <FlexibilityCanvas />}
|
||||
</Box>
|
||||
</Card>
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ export function ShellBorder(props: ComponentProps<'svg'>) {
|
||||
<path
|
||||
d="M149.917 7.5L151.5 9.91406V50.085L149.917 52.5H134.674C133.504 51.6657 132.116 51.1813 130.673 51.1133L130.319 51.1045H93.085C91.8919 51.1046 90.7173 51.3895 89.6582 51.9336L89.4482 52.0459L88.6494 52.4883C48.806 52.0806 22.9344 39.046 11.1416 30C22.9344 20.954 48.806 7.91846 88.6494 7.51074L89.4482 7.9541C90.5611 8.57122 91.8125 8.89543 93.085 8.89551H130.319C131.888 8.89551 133.409 8.40216 134.674 7.5H149.917Z"
|
||||
stroke="currentColor"
|
||||
stroke-width="15"
|
||||
stroke-linejoin="round"
|
||||
strokeWidth="15"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
+11
-27
@@ -1,6 +1,6 @@
|
||||
import { I_HAT, J_HAT } from '@blitzkit/core';
|
||||
import { OrbitControls } from '@react-three/drei';
|
||||
import { invalidate, useThree } from '@react-three/fiber';
|
||||
import { invalidate, useFrame, useThree } from '@react-three/fiber';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { PerspectiveCamera, Vector3 } from 'three';
|
||||
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
||||
@@ -90,32 +90,18 @@ export function Controls({
|
||||
-13,
|
||||
).multiplyScalar(distanceScale);
|
||||
|
||||
useEffect(() => {
|
||||
if (!orbitControls.current || !doAutoRotate) return;
|
||||
const t0 = useRef(Date.now() / 1000);
|
||||
useFrame(() => {
|
||||
if (!doAutoRotate) return;
|
||||
|
||||
const t0 = Date.now() / 1000;
|
||||
let cancel = false;
|
||||
const now = Date.now() / 1000;
|
||||
const t = now - t0.current;
|
||||
|
||||
function frame() {
|
||||
if (!cancel) requestAnimationFrame(frame);
|
||||
|
||||
const now = Date.now() / 1000;
|
||||
const t = now - t0;
|
||||
|
||||
camera.position
|
||||
.copy(inspectModeInitialPosition)
|
||||
.applyAxisAngle(I_HAT, (Math.PI / 32) * Math.sin(t / 9))
|
||||
.applyAxisAngle(J_HAT, (-Math.PI / 16) * Math.sin(t / 7));
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
frame();
|
||||
|
||||
return () => {
|
||||
cancel = true;
|
||||
};
|
||||
}, [doAutoRotate, camera]);
|
||||
camera.position
|
||||
.copy(inspectModeInitialPosition)
|
||||
.applyAxisAngle(I_HAT, (Math.PI / 32) * Math.sin(t / 9))
|
||||
.applyAxisAngle(J_HAT, (-Math.PI / 16) * Math.sin(t / 7));
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribeTankopediaEphemeral = tankopediaEphemeralStore.subscribe(
|
||||
@@ -229,8 +215,6 @@ export function Controls({
|
||||
}, [camera, protagonistTank.id, antagonistTank.id]);
|
||||
|
||||
useEffect(() => {
|
||||
let isInitialIteration = true;
|
||||
|
||||
function handleWheel(event: WheelEvent) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
import { BLITZKIT_TANK_ICON_SIZE } from '@blitzkit/core';
|
||||
import { Canvas, invalidate } from '@react-three/fiber';
|
||||
import { invalidate } from '@react-three/fiber';
|
||||
import {
|
||||
forwardRef,
|
||||
Suspense,
|
||||
@@ -13,7 +13,6 @@ import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimi
|
||||
import { modelTransformEvent } from '../../../../../core/blitzkit/modelTransform';
|
||||
import { Pose, poseEvent } from '../../../../../core/blitzkit/pose';
|
||||
import { useEquipment } from '../../../../../hooks/useEquipment';
|
||||
import { useOnScreen } from '../../../../../hooks/useOnScreen';
|
||||
import { useTankModelDefinition } from '../../../../../hooks/useTankModelDefinition';
|
||||
import { Duel } from '../../../../../stores/duel';
|
||||
import { TankopediaEphemeral } from '../../../../../stores/tankopediaEphemeral';
|
||||
@@ -26,6 +25,7 @@ import {
|
||||
StaticArmor,
|
||||
type ThicknessRange,
|
||||
} from '../../../../Armor/components/StaticArmor';
|
||||
import { SmartCanvas } from '../../../../SmartCanvas';
|
||||
import { AutoClear } from './components/AutoClear';
|
||||
import { Controls } from './components/Control';
|
||||
import { InitialFogReveal } from './components/InitialFogReveal';
|
||||
@@ -65,7 +65,6 @@ export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
||||
const hideTankModelUnderArmor = TankopediaPersistent.use(
|
||||
(state) => state.hideTankModelUnderArmor,
|
||||
);
|
||||
const onScreen = useOnScreen(canvas);
|
||||
|
||||
useEffect(() => {
|
||||
if (rawDisplay === display) return;
|
||||
@@ -204,10 +203,9 @@ export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
||||
}, [display]);
|
||||
|
||||
return (
|
||||
<Canvas
|
||||
<SmartCanvas
|
||||
ref={canvas}
|
||||
scene={{ fog: naked ? undefined : fog.current }}
|
||||
frameloop={onScreen ? 'demand' : 'never'}
|
||||
gl={{
|
||||
clippingPlanes: [],
|
||||
localClippingEnabled: true,
|
||||
@@ -248,7 +246,7 @@ export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
||||
)}
|
||||
<Lighting display={display} />
|
||||
</Suspense>
|
||||
</Canvas>
|
||||
</SmartCanvas>
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user