简体   繁体   English

在three.js中更改gridhelper的宽度和高度?

[英]Change width and height of a gridhelper in three.js?

Gridhelper seems to only have size which makes it square. Gridhelper似乎只有大小才能使它成为正方形。 Can't it be a rectangle where I can define a width and a height or maybe there's another way for me to do that in three.js? 不能是一个矩形,我可以定义宽度和高度,或者我可以用另一种方式在three.js中做到这一点? I think it might have 'scale' but that will make the divisions warp. 我认为它可能具有“规模”,但这会使分裂变形。

var size = 50;
var divisions = 10;

var gridHelper = new THREE.GridHelper(size, divisions);
scene.add(gridHelper);

Found a solution at bocoup: https://bocoup.com/blog/learning-three-js-with-real-world-challenges-that-have-already-been-solved 在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;
}

But had to change 但不得不改变

var line = new THREE.Line(gridGeo, material, THREE.LinePieces);

(deprecated) to (已弃用)

var line = new THREE.LineSegments(gridGeo, material);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM