Skip to content

Commit

Permalink
Merge pull request #80 from cgtuebingen/feature/renderer-refactor
Browse files Browse the repository at this point in the history
Renderer refactor
  • Loading branch information
Courtsilius authored Jul 10, 2024
2 parents 6e7fc02 + 5786237 commit e70b509
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 368 deletions.
60 changes: 47 additions & 13 deletions app/components/CanvasLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
StatsGl
} from '@react-three/drei';
import { FirstPersonControls } from './FirstPersonControls.tsx'
import TeleportControls from './TeleportControls.tsx';

import { TeleportControls } from './TeleportControls.tsx';
import { UserInterfaceRenderer } from './UserInterfaceRenderer.tsx';
import { Splat } from './Splat.tsx';
import { Leva, useControls } from 'leva';
import { useMemo } from 'react'
Expand All @@ -20,6 +20,28 @@ const CanvasLayer = () => {

const teleportControlsRef = useRef();

const [currentRoom, setCurrentRoom] = useState('');
const [currentSplats, setCurrentSplats] = useState([]);
const [currentKey, setCurrentKey] = useState('');

const updateCurrentRoom = (newRoom) => {

if(currentRoom == newRoom || newRoom == '' || newRoom == undefined) {
return;
}
setCurrentRoom(newRoom);
// get adjacent splats from currentRoom
if(newRoom.adjacent.length == 0) {
setCurrentSplats(newRoom.splat);
} else {
setCurrentSplats([...newRoom.adjacent.map(adjacentName => {
const adjacentRoom = roomConfig.find(room => room.name === adjacentName);
return adjacentRoom ? adjacentRoom.splat : null;
}).filter(splat => splat !== null), newRoom.splat]);
}
setCurrentKey(`${newRoom.name}${newRoom.adjacent.join('')}`)
}

useEffect(() => {
const checkFileExists = async () => {
try {
Expand All @@ -37,25 +59,41 @@ const CanvasLayer = () => {
checkFileExists();
}, []);


const options = useMemo(() => {
return {
speed: { value: 100, min: 1, max: 500, step: 10 },
debug: false,
}
}, [])

const splatOptions = useControls('Admin Panel', options);

const handleTeleport = () => {
if (teleportControlsRef.current) {
// Test cooordinates
// Test coordinates
// (posX, posY, posZ, lookAtX, lookAtY, lookAtZ)
teleportControlsRef.current.teleport(0, 0, 0, 0, 2, 1);
// here you teleprot to pos 0,0,0 and look at pos 0,2,1
teleportControlsRef.current.teleport(0, 0, 5.3, 0, 1, 1);
// here you teleport to pos 0,0,0 and look at pos 0,2,1
}
};

// temporary location for rooms
const roomConfig = [
{
splat: "https://huggingface.co/cakewalk/splat-data/resolve/main/nike.splat",
name: "room1",
adjacent: [],
minX: -100, maxX: 100, minY: 0, maxY: 5, minZ: -100, maxZ: 100,
slopes: [],
objects: [],
elements: {
arrows: [],
panes: [],
windowarcs: []
}
}

];
return (
<div className="absolute w-full h-full">
<div onMouseEnter={handleOverlayEnter} onMouseLeave={handleOverlayLeave}>
Expand All @@ -68,15 +106,11 @@ const CanvasLayer = () => {
<StatsGl />
<ambientLight />
<pointLight position={[0, 0, 0]} />
<FirstPersonControls speed={splatOptions.speed} />
<FirstPersonControls speed={splatOptions.speed} rooms={roomConfig} updateCurrentRoom={updateCurrentRoom}/>
<UserInterfaceRenderer rooms={roomConfig} debug={splatOptions.debug}/>
<TeleportControls ref={teleportControlsRef} />
{isPointerLocked && <PointerLockControls />}
{splatExists &&
<Splat position={[0, 2, 1]} src="splat.splat" /> }
{!splatExists &&
<Splat
position={[0, 2, 1]}
src="https://huggingface.co/cakewalk/splat-data/resolve/main/nike.splat" />}
{currentSplats.length > 0 && <Splat position={[0, 0, 0]} src={currentSplats} key={currentKey} />}
</Canvas>
</div>
);
Expand Down
Loading

0 comments on commit e70b509

Please sign in to comment.