[英]Change width and height of a gridhelper in three.js?
Gridhelper似乎只有大小才能使它成為正方形。 不能是一個矩形,我可以定義寬度和高度,或者我可以用另一種方式在three.js中做到這一點? 我認為它可能具有“規模”,但這會使分裂變形。
var size = 50;
var divisions = 10;
var gridHelper = new THREE.GridHelper(size, divisions);
scene.add(gridHelper);
在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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.