mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
wip
This commit is contained in:
parent
44e290f475
commit
2cf084f0bb
@ -34,9 +34,9 @@ export default function useThree() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
let afterInitHandlers = [];
|
let afterInitCallbacks = [];
|
||||||
let afterResizeHandlers = [];
|
let afterResizeCallbacks = [];
|
||||||
let beforeRenderHandlers = [];
|
let beforeRenderCallbacks = [];
|
||||||
|
|
||||||
// mouse tracking
|
// mouse tracking
|
||||||
const mouse = new Vector2();
|
const mouse = new Vector2();
|
||||||
@ -113,7 +113,7 @@ export default function useThree() {
|
|||||||
obj.mouse_move_element.addEventListener('mouseleave', onMouseleave);
|
obj.mouse_move_element.addEventListener('mouseleave', onMouseleave);
|
||||||
}
|
}
|
||||||
|
|
||||||
afterInitHandlers.forEach(c => c());
|
afterInitCallbacks.forEach(c => c());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -122,35 +122,35 @@ export default function useThree() {
|
|||||||
* add after init callback
|
* add after init callback
|
||||||
*/
|
*/
|
||||||
function onAfterInit(callback) {
|
function onAfterInit(callback) {
|
||||||
afterInitHandlers.push(callback);
|
afterInitCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add after resize callback
|
* add after resize callback
|
||||||
*/
|
*/
|
||||||
function onAfterResize(callback) {
|
function onAfterResize(callback) {
|
||||||
afterResizeHandlers.push(callback);
|
afterResizeCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove after resize callback
|
* remove after resize callback
|
||||||
*/
|
*/
|
||||||
function offAfterResize(callback) {
|
function offAfterResize(callback) {
|
||||||
afterResizeHandlers = afterResizeHandlers.filter(c => c !== callback);
|
afterResizeCallbacks = afterResizeCallbacks.filter(c => c !== callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add before render callback
|
* add before render callback
|
||||||
*/
|
*/
|
||||||
function onBeforeRender(callback) {
|
function onBeforeRender(callback) {
|
||||||
beforeRenderHandlers.push(callback);
|
beforeRenderCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove before render callback
|
* remove before render callback
|
||||||
*/
|
*/
|
||||||
function offBeforeRender(callback) {
|
function offBeforeRender(callback) {
|
||||||
beforeRenderHandlers = beforeRenderHandlers.filter(c => c !== callback);
|
beforeRenderCallbacks = beforeRenderCallbacks.filter(c => c !== callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,7 +158,7 @@ export default function useThree() {
|
|||||||
*/
|
*/
|
||||||
function render() {
|
function render() {
|
||||||
if (obj.orbitCtrl) obj.orbitCtrl.update();
|
if (obj.orbitCtrl) obj.orbitCtrl.update();
|
||||||
beforeRenderHandlers.forEach(c => c());
|
beforeRenderCallbacks.forEach(c => c());
|
||||||
obj.renderer.render(obj.scene, obj.camera);
|
obj.renderer.render(obj.scene, obj.camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ export default function useThree() {
|
|||||||
*/
|
*/
|
||||||
function renderC() {
|
function renderC() {
|
||||||
if (obj.orbitCtrl) obj.orbitCtrl.update();
|
if (obj.orbitCtrl) obj.orbitCtrl.update();
|
||||||
beforeRenderHandlers.forEach(c => c());
|
beforeRenderCallbacks.forEach(c => c());
|
||||||
obj.composer.render();
|
obj.composer.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ export default function useThree() {
|
|||||||
* remove listeners
|
* remove listeners
|
||||||
*/
|
*/
|
||||||
function dispose() {
|
function dispose() {
|
||||||
beforeRenderHandlers = [];
|
beforeRenderCallbacks = [];
|
||||||
window.removeEventListener('resize', onResize);
|
window.removeEventListener('resize', onResize);
|
||||||
if (obj.mouse_move_element) {
|
if (obj.mouse_move_element) {
|
||||||
obj.mouse_move_element.removeEventListener('mousemove', onMousemove);
|
obj.mouse_move_element.removeEventListener('mousemove', onMousemove);
|
||||||
@ -224,7 +224,7 @@ export default function useThree() {
|
|||||||
} else {
|
} else {
|
||||||
setSize(conf.resize.clientWidth, conf.resize.clientHeight);
|
setSize(conf.resize.clientWidth, conf.resize.clientHeight);
|
||||||
}
|
}
|
||||||
afterResizeHandlers.forEach(c => c());
|
afterResizeCallbacks.forEach(c => c());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user