mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-07-16 00:44:59 +00:00
fix TorqueObject property type parsing
This commit is contained in:
parent
de2007f2f7
commit
84ea543135
4 changed files with 34 additions and 17 deletions
|
|
@ -2,7 +2,7 @@ import { memo, useEffect, useRef } from "react";
|
||||||
import { useThree, useFrame } from "@react-three/fiber";
|
import { useThree, useFrame } from "@react-three/fiber";
|
||||||
import { PositionalAudio, Vector3 } from "three";
|
import { PositionalAudio, Vector3 } from "three";
|
||||||
import type { TorqueObject } from "../torqueScript";
|
import type { TorqueObject } from "../torqueScript";
|
||||||
import { getPosition, getProperty } from "../mission";
|
import { getFloat, getInt, getPosition, getProperty } from "../mission";
|
||||||
import { audioToUrl } from "../loaders";
|
import { audioToUrl } from "../loaders";
|
||||||
import { useAudio } from "./AudioContext";
|
import { useAudio } from "./AudioContext";
|
||||||
import { useDebug, useSettings } from "./SettingsProvider";
|
import { useDebug, useSettings } from "./SettingsProvider";
|
||||||
|
|
@ -40,12 +40,12 @@ export const AudioEmitter = memo(function AudioEmitter({
|
||||||
}) {
|
}) {
|
||||||
const { debugMode } = useDebug();
|
const { debugMode } = useDebug();
|
||||||
const fileName = getProperty(object, "fileName") ?? "";
|
const fileName = getProperty(object, "fileName") ?? "";
|
||||||
const volume = getProperty(object, "volume") ?? 1;
|
const volume = getFloat(object, "volume") ?? 1;
|
||||||
const minDistance = getProperty(object, "minDistance") ?? 1;
|
const minDistance = getFloat(object, "minDistance") ?? 1;
|
||||||
const maxDistance = getProperty(object, "maxDistance") ?? 1;
|
const maxDistance = getFloat(object, "maxDistance") ?? 1;
|
||||||
const minLoopGap = getProperty(object, "minLoopGap") ?? 0;
|
const minLoopGap = getFloat(object, "minLoopGap") ?? 0;
|
||||||
const maxLoopGap = getProperty(object, "maxLoopGap") ?? 0;
|
const maxLoopGap = getFloat(object, "maxLoopGap") ?? 0;
|
||||||
const is3D = getProperty(object, "is3D") ?? 0;
|
const is3D = getInt(object, "is3D") ?? 0;
|
||||||
|
|
||||||
const [x, y, z] = getPosition(object);
|
const [x, y, z] = getPosition(object);
|
||||||
const { scene, camera } = useThree();
|
const { scene, camera } = useThree();
|
||||||
|
|
@ -209,7 +209,7 @@ export const AudioEmitter = memo(function AudioEmitter({
|
||||||
transparent
|
transparent
|
||||||
toneMapped={false}
|
toneMapped={false}
|
||||||
/>
|
/>
|
||||||
<FloatingLabel color="#00ff00" position={[0, minDistance, 0]}>
|
<FloatingLabel color="#00ff00" position={[0, minDistance + 1, 0]}>
|
||||||
{fileName}
|
{fileName}
|
||||||
</FloatingLabel>
|
</FloatingLabel>
|
||||||
</mesh>
|
</mesh>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||||
import { useCubeTexture } from "@react-three/drei";
|
import { useCubeTexture } from "@react-three/drei";
|
||||||
import { Color, ShaderMaterial, BackSide, Euler } from "three";
|
import { Color, ShaderMaterial, BackSide, Euler } from "three";
|
||||||
import type { TorqueObject } from "../torqueScript";
|
import type { TorqueObject } from "../torqueScript";
|
||||||
import { getProperty } from "../mission";
|
import { getFloat, getProperty } from "../mission";
|
||||||
import { useSettings } from "./SettingsProvider";
|
import { useSettings } from "./SettingsProvider";
|
||||||
import { BASE_URL, getUrlForPath, loadDetailMapList } from "../loaders";
|
import { BASE_URL, getUrlForPath, loadDetailMapList } from "../loaders";
|
||||||
import { useThree } from "@react-three/fiber";
|
import { useThree } from "@react-three/fiber";
|
||||||
|
|
@ -148,9 +148,7 @@ export function Sky({ object }: { object: TorqueObject }) {
|
||||||
|
|
||||||
// Fog parameters.
|
// Fog parameters.
|
||||||
// TODO: There can be multiple fog volumes/layers. Render simple fog for now.
|
// TODO: There can be multiple fog volumes/layers. Render simple fog for now.
|
||||||
const fogDistance = useMemo(() => {
|
const fogDistance = getFloat(object, "fogDistance");
|
||||||
return getProperty(object, "fogDistance");
|
|
||||||
}, [object]);
|
|
||||||
|
|
||||||
const fogColor = useMemo(() => {
|
const fogColor = useMemo(() => {
|
||||||
const colorString = getProperty(object, "fogColor");
|
const colorString = getProperty(object, "fogColor");
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,13 @@ import { useTexture } from "@react-three/drei";
|
||||||
import { uint16ToFloat32 } from "../arrayUtils";
|
import { uint16ToFloat32 } from "../arrayUtils";
|
||||||
import { loadTerrain, terrainTextureToUrl } from "../loaders";
|
import { loadTerrain, terrainTextureToUrl } from "../loaders";
|
||||||
import type { TorqueObject } from "../torqueScript";
|
import type { TorqueObject } from "../torqueScript";
|
||||||
import { getPosition, getProperty, getRotation, getScale } from "../mission";
|
import {
|
||||||
|
getInt,
|
||||||
|
getPosition,
|
||||||
|
getProperty,
|
||||||
|
getRotation,
|
||||||
|
getScale,
|
||||||
|
} from "../mission";
|
||||||
import {
|
import {
|
||||||
setupColor,
|
setupColor,
|
||||||
setupMask,
|
setupMask,
|
||||||
|
|
@ -202,10 +208,7 @@ export const TerrainBlock = memo(function TerrainBlock({
|
||||||
object: TorqueObject;
|
object: TorqueObject;
|
||||||
}) {
|
}) {
|
||||||
const terrainFile = getProperty(object, "terrainFile");
|
const terrainFile = getProperty(object, "terrainFile");
|
||||||
|
const squareSize = getInt(object, "squareSize") ?? DEFAULT_SQUARE_SIZE;
|
||||||
const squareSize = useMemo(() => {
|
|
||||||
return getProperty(object, "squareSize") ?? DEFAULT_SQUARE_SIZE;
|
|
||||||
}, [object]);
|
|
||||||
|
|
||||||
const emptySquares: number[] = useMemo(() => {
|
const emptySquares: number[] = useMemo(() => {
|
||||||
const emptySquaresValue = getProperty(object, "emptySquares");
|
const emptySquaresValue = getProperty(object, "emptySquares");
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,22 @@ export function getProperty(obj: TorqueObject, name: string): any {
|
||||||
return obj[name.toLowerCase()];
|
return obj[name.toLowerCase()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFloat(
|
||||||
|
obj: TorqueObject,
|
||||||
|
name: string,
|
||||||
|
): number | null | undefined {
|
||||||
|
const value = obj[name.toLowerCase()];
|
||||||
|
return value == null ? value : parseFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInt(
|
||||||
|
obj: TorqueObject,
|
||||||
|
name: string,
|
||||||
|
): number | null | undefined {
|
||||||
|
const value = obj[name.toLowerCase()];
|
||||||
|
return value == null ? value : parseInt(value, 10);
|
||||||
|
}
|
||||||
|
|
||||||
export function getPosition(obj: TorqueObject): [number, number, number] {
|
export function getPosition(obj: TorqueObject): [number, number, number] {
|
||||||
const position = obj.position ?? "0 0 0";
|
const position = obj.position ?? "0 0 0";
|
||||||
const [x, y, z] = position.split(" ").map((s: string) => parseFloat(s));
|
const [x, y, z] = position.split(" ").map((s: string) => parseFloat(s));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue