Skip to content

Instantly share code, notes, and snippets.

@ngarske
Created August 12, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngarske/c568a7f9e5890754ee02064a77763535 to your computer and use it in GitHub Desktop.
Save ngarske/c568a7f9e5890754ee02064a77763535 to your computer and use it in GitHub Desktop.
Lets make some 3D in Svelte: Part 2
<script lang="ts">
import {
CircleBufferGeometry,
MeshStandardMaterial,
DoubleSide,
BoxBufferGeometry,
} from "three";
import {
AmbientLight,
DirectionalLight,
Group,
Mesh,
OrbitControls,
PerspectiveCamera,
useFrame,
} from "@threlte/core";
import { useLoader } from "@threlte/core";
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
let rotation = 0;
const loader = useLoader(OBJLoader, () => new OBJLoader());
loader.load("island.obj", (obj) => {
console.log(obj.children[0]);
island = obj;
});
useFrame(() => {
rotation += 0.01;
});
let island = null;
</script>
<PerspectiveCamera position={{ x: 30, y: 10, z: 5 }} fov={24}>
<OrbitControls
target={{ y: 3 }}
/>
</PerspectiveCamera>
<DirectionalLight shadow position={{ x: 10, y: 10, z: 10 }} />
<AmbientLight intensity={0.2} />
{#if island != null}
<Group position={{ y: 2 }}>
<Mesh
interactive
castShadow
recieveShadow
geometry={island.children[0].geometry}
material={new MeshStandardMaterial()}
/>
</Group>
{/if}
<!-- Floor -->
<Mesh
receiveShadow
rotation={{ x: -90 * (Math.PI / 180) }}
geometry={new CircleBufferGeometry(4, 72)}
material={new MeshStandardMaterial({ side: DoubleSide, color: "white" })}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment