Skip to content

Commit

Permalink
feat - add appartment v4
Browse files Browse the repository at this point in the history
  • Loading branch information
sdubourg committed Jul 26, 2023
1 parent 854e79b commit c503434
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 14,773 deletions.
8,090 changes: 0 additions & 8,090 deletions HOUSE_LOW_POLY_WIP.gltf

This file was deleted.

6,351 changes: 0 additions & 6,351 deletions appartment_v1.gltf

This file was deleted.

Binary file not shown.

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/components/gl/House/HotSpots/AppartmentHotspot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from 'react';
import { shallow } from 'zustand/shallow';
import { useStoreDragging } from '../../../../stores/storeDragging';
import type { AppartmentHotSpot } from './types';
import { useCursor } from '@react-three/drei';

export const AppartmentHotspot = ({
geometry,
Expand All @@ -14,6 +15,7 @@ export const AppartmentHotspot = ({
}: AppartmentHotSpot & MeshProps) => {
const [isHovered, setIsHovered] = useState(false);
const service = useInterpret(hotSpotMachine);
useCursor(isHovered);

// TODO : use below solution when availble ===> registers hotspot machine in game machine
// const gameMachine = useGameMachineProvider();
Expand All @@ -38,7 +40,7 @@ export const AppartmentHotspot = ({

// setup easings
const { glow, scale } = useSpring({
glow: isHovered ? 2 : 1,
glow: isHovered ? 3 : 1,
scale: isHovered ? [1, 1.05, 1.05] : [1, 1, 1],
});

Expand All @@ -48,31 +50,29 @@ export const AppartmentHotspot = ({
setDraggingId(null);

draggingActorRef &&
service.send({ type: 'onAddPerson', person: draggingActorRef });
service.send({
type: 'onAddPerson',
person: draggingActorRef,
});
}
};

return (
// @ts-ignore
<a.group scale={scale} onClick={handleOnClick}>
<mesh
{/* @ts-ignore */}
<a.mesh
onPointerEnter={() => setIsHovered(true)}
onPointerLeave={() => setIsHovered(false)}
geometry={geometry}
material={materials}
{...props}
>
{/* @ts-ignore */}
<a.meshLambertMaterial
map={materials.map} // TODO: render some button in a different RenderTexture, to control light pulsing diffrent rythm
alphaTest={0.1}
transparent
toneMapped={false}
emissive={0xffffff}
emissiveMap={materials.map}
emissiveIntensity={glow}
/>
</mesh>
material-tonedMapped={false}
material-emissive={0xffffff}
material-emissiveIntensity={glow}
material-map={materials.map}
material-emissiveMap={materials.map}
/>
</a.group>
);
};
57 changes: 3 additions & 54 deletions src/components/gl/Person/Person.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const Person = ({
const ref = useRef<Mesh>(null);
const beforeDragPosition = useRef<Vector3>(new Vector3(0, 0, 0));
const refGroup = useRef<Group>(null);
const refShadow = useRef<Mesh>(null);
const tex = useTexture('assets/dudess.png');
const serviceId = actor.id;

Expand All @@ -66,15 +65,6 @@ export const Person = ({

const isBeingDragged = draggingId === serviceId;

// init easings
const shadow = useSpring({
opacity: isBeingDragged ? 0.9 : 0.1,
color: isBeingDragged ? '#FFA500' : 'grey',
scale: isBeingDragged
? ([1.25, 1.25, 1.25] as const)
: ([0.75, 0.75, 0.75] as const),
});

// position tick for the drag back shadow
useEffect(() => {
if (isBeingDragged && refGroup.current) {
Expand All @@ -86,41 +76,20 @@ export const Person = ({
useEffect(() => {
if (ref.current && refGroup.current && !isExists.current) {
ref.current.geometry.translate(0, PERSON_HEIGHT * 0.5, 0);
refGroup.current.position.copy(pos || new Vector3(-31, 0, 9));
refGroup.current.position.copy(pos || new Vector3(-31, 0, 11.5));
isExists.current = true;
actor.send('triggerStart');
}
}, [isExists, pos, actor]);

useFrame(({ raycaster, camera, clock }) => {
useFrame(({ camera, clock }) => {
if (!ref.current || !refGroup.current || !refFloor) {
return;
}

// const intersects =
// refFloor.current && raycaster.intersectObject(refFloor.current);

// drag
// if (intersects && intersects.length > 0 && isBeingDragged) {
// const [intersect] = intersects;
// if (isDragging) {
// const newGroupPos = new Vector3(
// intersect.point.x,
// 0,
// intersect.point.z,
// );
// refGroup.current.position.lerp(newGroupPos, 0.1);
// ref.current.position.y = MathUtils.lerp(
// ref.current.position.y,
// PERSON_HEIGHT * 0.15,
// 0.2,
// );
// }
// }

if (isBeingDragged) {
refGroup.current.position.lerp(
new Vector3(camera.position.x, refGroup.current.position.y, 8),
new Vector3(camera.position.x, refGroup.current.position.y, 11),
0.75,
);
}
Expand Down Expand Up @@ -168,26 +137,6 @@ export const Person = ({
<Statbar position-y={6.25} value={pee} />
<Statbar position-y={6.5} value={hype} />

<a.mesh
ref={refShadow}
rotation-x={Math.PI * -0.5}
position-y={-1.1}
scale={shadow.scale}
>
<circleBufferGeometry />

{/* @ts-ignore */}
<a.meshLambertMaterial
transparent
opacity={shadow.opacity}
depthWrite={false}
color={shadow.color}
toneMapped={false}
emissive={0xf4f400}
emissiveIntensity={0.15}
/>
</a.mesh>

{/* Debug */}
{showActionButtons && (
<Html>
Expand Down
5 changes: 4 additions & 1 deletion src/components/gl/Person/PersonShadowRecall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const PersonShadowRecall = ({
if (refShadowRecall.current) {
refShadowRecall.current.position.set(
beforeDragPosition.x,
-0.9,
-1.5,
beforeDragPosition.z,
);
}
Expand All @@ -43,6 +43,9 @@ export const PersonShadowRecall = ({
opacity={shadow.opacity}
depthWrite={false}
color={shadow.color}
toneMapped={false}
emissive={0xffffff}
emissiveIntensity={1.2}
/>
</a.mesh>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/gl/Scene/Scene.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Canvas } from '@react-three/fiber';
import { World } from '../World/World';
import { Stars } from '@react-three/drei';

export const Scene = () => {
return (
Expand All @@ -8,6 +9,8 @@ export const Scene = () => {
gl={{ alpha: true, antialias: true }}
style={{ width: '100vw', height: '100vh' }}
>
<Stars />
<color attach="background" args={['purple']} />
<ambientLight intensity={1.5} />

<World />
Expand Down
6 changes: 3 additions & 3 deletions src/components/gl/World/Cam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const Cam = () => {
distance={23}
truckSpeed={4}
// truckSpeed={isDragging ? -4 : 4}
polarAngle={DEG2RAD * 85}
minPolarAngle={DEG2RAD * 85}
maxPolarAngle={DEG2RAD * 85}
polarAngle={DEG2RAD * 87}
minPolarAngle={DEG2RAD * 87}
maxPolarAngle={DEG2RAD * 87}
mouseButtons={{
left: 2,
wheel: 0,
Expand Down
32 changes: 4 additions & 28 deletions src/components/gl/World/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,10 @@ import { useSelector } from '@xstate/react';
import { Suspense, useRef } from 'react';
import type { Mesh } from 'three';
import { useGameMachineProvider } from '../../../hooks/use';
import { Bar } from '../Environment/HotSpot/Bar';
import { Toilet } from '../Environment/HotSpot/Toilet';
import { AppartmentModel } from '../House/Appartment_v1';
import { Person } from '../Person/Person';
import { Cam } from './Cam';
import { useFrame } from '@react-three/fiber';
import { PostProcess } from '../postProcess/PostProcess';

function Debug() {
const ref = useRef<Mesh>(null);

useFrame(({ camera }) => {
if (!ref.current) {
return;
}

ref.current.position.copy(camera.position);
ref.current.position.z = 20;
});

return (
<mesh ref={ref}>
<boxBufferGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="red" />
</mesh>
);
}
import { Cam } from './Cam';
import { AppartmentV4 } from '../House/Appartment_v4';

export const World = () => {
const refFloor = useRef<Mesh>(null);
Expand All @@ -39,9 +16,9 @@ export const World = () => {
<>
<Cam />

{/* <HouseModel ref={refFloor} /> */}
{/* <AppartmentModelv3 ref={refFloor} position-y={-0.5} /> */}

<AppartmentModel ref={refFloor} />
<AppartmentV4 ref={refFloor} position-y={-0.5} />

<Suspense fallback={null}>
{persons.map((actor) => (
Expand All @@ -50,7 +27,6 @@ export const World = () => {
</Suspense>

<PostProcess />
{/* <Debug /> */}
</>
);
};
7 changes: 5 additions & 2 deletions src/machines/person.machine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MathUtils } from 'three';
import { assign, createMachine } from 'xstate';
import { assign, createMachine, send } from 'xstate';

Check warning on line 2 in src/machines/person.machine.ts

View workflow job for this annotation

GitHub Actions / main - Build and deploy

'send' is defined but never used

Check failure on line 2 in src/machines/person.machine.ts

View workflow job for this annotation

GitHub Actions / main - Build and deploy

'send' is declared but its value is never read.
import { sendTo } from 'xstate/lib/actions';

Check warning on line 3 in src/machines/person.machine.ts

View workflow job for this annotation

GitHub Actions / main - Build and deploy

'sendTo' is defined but never used

Check failure on line 3 in src/machines/person.machine.ts

View workflow job for this annotation

GitHub Actions / main - Build and deploy

'sendTo' is declared but its value is never read.

const METERS_CONFIG = {
thirst: {
Expand Down Expand Up @@ -276,7 +277,9 @@ export const personMachine = createMachine(
...context,
hotspot: event.hotspot,
})),
unregisterHotspot: assign((context) => ({ ...context, hotspot: '' })),
unregisterHotspot: assign((context) => {
return { ...context, hotspot: '' };
}),
},
guards: {
isPeeEmpty: (context) => context.meters.pee <= 0,
Expand Down
Loading

0 comments on commit c503434

Please sign in to comment.