2012-07-09 186 views
3

我可以在Three.js中使用stencilFunc和stencilOp函數嗎? 我試圖實現模板測試的代碼,但沒有奏效。如何在Three.js中使用stencilFunc函數

var scene = new THREE.Scene(); 
var renderer = new THREE.WebGLRenderer({ 
    antialias: true, 
    stencil: true 
}); 

function render() { 
    var context = renderer.context; 

    context.enable(context.STENCIL_TEST); 
    context.stencilFunc(context.ALWAYS, 0, 0xffffffff); 
    context.stencilOp(context.REPLACE, context.REPLACE, context.REPLACE); 
    context.clearStencil(0); 
    context.clear(context.COLOR_BUFFER_BIT, context.DEPTH_BUFFER_BIT, context.STENCIL_BUFFER_BIT); 

    renderer.render(scene, camera); 
    context.stencilFunc(context.EQUAL, 1, 0xffffffff); 
    context.stencilOp(context.KEEP, context.KEEP, context.KEEP); 

    context.disable(context.STENCIL_TEST); 
    context.flush(); 
} 

回答

0

當您創建WebGL的渲染器,默認情況下它會是真實的,因爲每threeJS文檔

http://threejs.org/docs/#Reference/Renderers/WebGLRenderer

可以直接調用clearStencil(),從描繪對象,因爲其渲染器的行爲,不確定爲什麼要從上下文中調用它。還有,在ThreeJs webGL渲染器類中不存在一些您在代碼中調用的函數。

下面是鏈接到類源代碼。請檢查

https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js