1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/App.vue

45 lines
1.2 KiB
Vue
Raw Normal View History

2020-09-14 22:57:11 +08:00
<template>
2021-04-27 01:09:06 +08:00
<Renderer ref="renderer" antialias :pointer="{ resetOnEnd: true }" :orbit-ctrl="{ enableDamping: true }" resize="window">
2021-03-01 04:01:56 +08:00
<Camera :position="{ z: 10 }" />
<Scene>
<PointLight :position="{ y: 50, z: 50 }" />
2021-04-27 01:09:06 +08:00
<Box :size="1" ref="box" :rotation="{ y: Math.PI / 4, z: Math.PI / 4 }">
2021-03-13 06:16:34 +08:00
<LambertMaterial />
2021-03-01 04:01:56 +08:00
</Box>
</Scene>
</Renderer>
2020-09-14 22:57:11 +08:00
</template>
2021-04-27 01:09:06 +08:00
<script lang="ts">
import { defineComponent } from 'vue'
import Box from './meshes/Box'
import Camera from './core/PerspectiveCamera'
import LambertMaterial from './materials/LambertMaterial'
import { MeshInterface } from './meshes/Mesh'
import PointLight from './lights/PointLight'
import Renderer, { RendererInterface } from './core/Renderer'
import Scene from './core/Scene'
export default defineComponent({
components: { Box, Camera, LambertMaterial, PointLight, Renderer, Scene },
2021-03-01 04:01:56 +08:00
mounted() {
2021-04-27 01:09:06 +08:00
const renderer = this.$refs.renderer as RendererInterface
const mesh = (this.$refs.box as MeshInterface).mesh
if (renderer && mesh) {
renderer.onBeforeRender(() => {
mesh.rotation.x += 0.01
})
}
2021-03-01 04:01:56 +08:00
},
2021-04-27 01:09:06 +08:00
})
2020-09-14 22:57:11 +08:00
</script>
2020-09-15 16:07:57 +08:00
2021-03-13 06:16:34 +08:00
<style>
body, html {
2021-03-01 04:01:56 +08:00
margin: 0;
}
2021-03-13 06:16:34 +08:00
canvas {
display: block;
2020-09-15 16:07:57 +08:00
}
</style>