Gridhelper的大小似乎只能使其为正方形。难道不是可以定义宽度和高度的矩形,还是在three.js中有另一种方式可以做到这一点?我认为它可能具有“规模”,但这将使部门翘曲。
var size = 50;
var divisions = 10;
var gridHelper = new THREE.GridHelper(size, divisions);
scene.add(gridHelper);
答案 0 :(得分:0)
在bocoup找到了一个解决方案:https://bocoup.com/blog/learning-three-js-with-real-world-challenges-that-have-already-been-solved
function createAGrid(opts) {
var config = opts || {
height: 500,
width: 500,
linesHeight: 10,
linesWidth: 10,
color: 0xDD006C
};
var material = new THREE.LineBasicMaterial({
color: config.color,
opacity: 0.2
});
var gridObject = new THREE.Object3D(),
gridGeo = new THREE.Geometry(),
stepw = 2 * config.width / config.linesWidth,
steph = 2 * config.height / config.linesHeight;
//width
for (var i = -config.width; i <= config.width; i += stepw) {
gridGeo.vertices.push(new THREE.Vector3(-config.height, i, 0));
gridGeo.vertices.push(new THREE.Vector3(config.height, i, 0));
}
//height
for (var i = -config.height; i <= config.height; i += steph) {
gridGeo.vertices.push(new THREE.Vector3(i, -config.width, 0));
gridGeo.vertices.push(new THREE.Vector3(i, config.width, 0));
}
var line = new THREE.Line(gridGeo, material, THREE.LinePieces);
gridObject.add(line);
return gridObject;
}
但必须更改
var line = new THREE.Line(gridGeo, material, THREE.LinePieces);
(不建议使用)
var line = new THREE.LineSegments(gridGeo, material);