[英]Adding diagonal lines to a GridHelper object in Three.js?
First image is what I want. 第一张图片就是我想要的。 (I even want the opposite diagonal too, but I will derive that accordingly.) Second image is a normal
GridHelper
. (我甚至也想要相反的对角线,但我会相应地得出它。)第二个图像是一个普通的
GridHelper
。
Would this be possible by adding another grid helper but rotated along the y-axis by 45 degrees? 这可以通过添加另一个网格助手但沿y轴旋转45度来实现吗?
I cannot seem to find anything in the official docs , so I am assuming that there is an alternate approach. 我似乎无法在官方文档中找到任何内容,因此我假设有另一种方法。 Any pointers on how this could be done?
关于如何做到这一点的任何指示?
My code for the GridHelper
: 我的
GridHelper
代码:
grid = new THREE.GridHelper(80, 15, 0x000000, 0x000000);
grid.position.y = -0.2;
scene.add(grid);
I am thinking that a possible solution may lie in EdgesGeometry
. 我想可能的解决方案可能在于
EdgesGeometry
。 I am still unsure about how to proceed with this, since: 我仍然不确定如何继续这样做,因为:
EdgesGeometry( geometry, thresholdAngle )
Where geometry
is any geometry object. geometry
是任何几何对象。
Does the GridHelper
count as a geometry object? GridHelper
是否算作几何对象? Here are the official docs . 这是官方文档 。
EDIT: Here is a visual example of my current situation: codepen example . 编辑:这是我目前情况的一个可视化示例: codepen示例 。
Using of THREE.PlaneBufferGeometry()
and a material with wireframe: true
will give you the desired result. 使用
THREE.PlaneBufferGeometry()
和一个带有wireframe: true
的材质将为您提供所需的结果。
var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000); camera.position.set(0, 50, 25); var renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setClearColor(0xffffff); document.body.appendChild(renderer.domElement); var controls = new THREE.OrbitControls(camera, renderer.domElement); var gridGeometry = new THREE.PlaneBufferGeometry(80, 80, 15, 15); gridGeometry.rotateY(Math.PI); gridGeometry.rotateX(-Math.PI * .5); var gridMaterial = new THREE.MeshBasicMaterial({ color: "black", wireframe: true }); var gridWithDiagonals = new THREE.Mesh(gridGeometry, gridMaterial); scene.add(gridWithDiagonals); render(); function render() { requestAnimationFrame(render); renderer.render(scene, camera); }
body { overflow: hidden; margin: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script> <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.