【问题标题】:How can I get my mesh has gone off screen?我怎样才能让我的网格离开屏幕?
【发布时间】:2012-10-18 23:47:04
【问题描述】:

我不知道如何检测它是否会离开屏幕,有人可以帮忙吗?我正在使用 WebGL 和 Three.js。

【问题讨论】:

    标签: javascript graphics position webgl three.js


    【解决方案1】:

    可以使用Frustum测试,有点像这样:

    // Create a new Frustum object (for efficiency, do this only once)
    var frustum = new THREE.Frustum();
    // Helper matrix (for efficiency, do this only once) 
    var projScreenMatrix = new THREE.Matrix4();
    
    // Set the matrix from camera matrices (which are updated on each renderer.render() call)
    projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
    // Update the frustum
    frustum.setFromMatrix( projScreenMatrix );
    // Test for visibility
    if ( !frustum.contains( object ) ) {
        // It's off-screen!
    }
    

    这是从WebGLRenderer sources复制的。

    【讨论】:

    • 当我尝试运行此代码时出现 TypeError: THREE.Frustum is not a constructor
    • 我一定有一个过时的 three.js 文件,现在可以使用了,谢谢!
    猜你喜欢
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多