1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

wip (core)

This commit is contained in:
Kevin Levron 2021-04-16 04:12:41 +02:00
parent de98dd8d11
commit 53a5f32344
8 changed files with 28 additions and 21 deletions

View File

@ -49,5 +49,8 @@ module.exports = {
// }],
// 'vue/valid-template-root': 'off',
'vue/no-multiple-template-root': 'off',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': ['warn'],
},
}

View File

@ -1,5 +1,5 @@
import { defineComponent } from 'vue'
// import Object3D from '../core/Object3D';
// import Object3D from '../core/Object3D'
export default defineComponent({
// TODO: eventually extend Object3D, for now: error 'injection "scene" not found'

View File

@ -31,7 +31,7 @@ export default defineComponent({
// TODO : fix lookat.x
if (this.lookAt) this.o3d.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z)
watch(() => this.lookAt, (v) => { this.o3d.lookAt(v.x, v.y, v.z); }, { deep: true })
watch(() => this.lookAt, (v) => { this.o3d.lookAt(v.x, v.y, v.z) }, { deep: true })
this._parent = this.getParent()
if (this.addToParent()) this.$emit('ready', this)

View File

@ -23,11 +23,12 @@ export default defineComponent({
}
},
created() {
bindProp(this, 'position', this.camera);
bindProp(this, 'position', this.camera)
['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom'].forEach(p => {
const watchProps = ['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom']
watchProps.forEach(p => {
watch(() => this[p], () => {
this.camera[p] = this[p];
this.camera[p] = this[p]
this.camera.updateProjectionMatrix()
})
})

View File

@ -18,6 +18,7 @@ export default defineComponent({
},
setup() {
const renderer: null | WebGLRenderer = null
const _render: {(): void} = () => {}
const onMountedCallbacks: {(): void}[] = []
const beforeRenderCallbacks: {(): void}[] = []
@ -27,6 +28,7 @@ export default defineComponent({
three: useThree(),
renderer,
raf: true,
_render,
onMountedCallbacks,
beforeRenderCallbacks,
afterRenderCallbacks,
@ -64,7 +66,7 @@ export default defineComponent({
} else {
requestAnimationFrame(this.renderLoop)
}
};
}
this.onMountedCallbacks.forEach(c => c())
},

View File

@ -16,8 +16,8 @@ export interface PointerIntersectEventInterface {
intersect?: Intersection
}
export type PointerCallbackType = (e: PointerEventInterface) => void
export type PointerIntersectCallbackType = (e: PointerIntersectEventInterface) => void
export type IntersectObject = Mesh | InstancedMesh
export interface PointerConfigInterface {
@ -29,15 +29,15 @@ export interface PointerConfigInterface {
resetOnEnd?: boolean
resetPosition?: Vector2
resetPositionV3?: Vector3
onEnter?(e: PointerEventInterface): void
onMove?(e: PointerEventInterface): void
onLeave?(e: PointerEventInterface): void
onClick?(e: PointerEventInterface): void
onIntersectEnter: PointerIntersectCallbackType
onIntersectOver: PointerIntersectCallbackType
onIntersectMove: PointerIntersectCallbackType
onIntersectLeave: PointerIntersectCallbackType
onIntersectClick: PointerIntersectCallbackType
onEnter?: PointerCallbackType
onMove?: PointerCallbackType
onLeave?: PointerCallbackType
onClick?: PointerCallbackType
onIntersectEnter?: PointerIntersectCallbackType
onIntersectOver?: PointerIntersectCallbackType
onIntersectMove?: PointerIntersectCallbackType
onIntersectLeave?: PointerIntersectCallbackType
onIntersectClick?: PointerIntersectCallbackType
}
export interface PointerInterface {

View File

@ -1,4 +1,4 @@
import { Camera, Intersection, Plane, Raycaster, Vector2, Vector3 } from 'three';
import { Camera, Intersection, Plane, Raycaster, Vector2, Vector3 } from 'three'
import { IntersectObject } from './usePointer'
export interface RaycasterInterface {

View File

@ -73,9 +73,9 @@ export default function useThree(): ThreeInterface {
// const afterInitCallbacks: void[] = []
// let afterResizeCallbacks: void[] = []
// let beforeRenderCallbacks: void[] = []
const afterInitCallbacks: {(): void;}[] = []
let afterResizeCallbacks: {(): void;}[] = []
let beforeRenderCallbacks: {(): void;}[] = []
const afterInitCallbacks: {(): void}[] = []
let afterResizeCallbacks: {(): void}[] = []
let beforeRenderCallbacks: {(): void}[] = []
const intersectObjects: IntersectObject[] = []
@ -294,7 +294,8 @@ export default function useThree(): ThreeInterface {
size.wHeight = oCamera.top - oCamera.bottom
} else {
const wsize = getCameraSize()
size.wWidth = wsize[0]; size.wHeight = wsize[1]
size.wWidth = wsize[0]
size.wHeight = wsize[1]
}
}