如何在Three.js中访问material.resolution

huangapple go评论65阅读模式
英文:

How to access material.resolution in Three.js

问题

我正在按照这个教程进行操作,尝试根据不同的坐标绘制粗线。

https://github.com/leighhalliday/google-maps-threejs/blob/main/pages/car.js

我的代码卡在这里

trackRef.current.material.resolution.copy(
  overlayRef.current.getViewportSize()
);

因为材质中没有 'resolution' 属性。

我用于绘制粗线的代码如下:

const lineGeometry = new LineGeometry().setPositions(positions);
const lineMaterial = new THREE.LineBasicMaterial({
  color: 0xff0000,
  linewidth: 8,
});
const line = new Line2(lineGeometry, lineMaterial);

我如何访问 material.resolution,或者是否有其他方法来实现相同的效果?

英文:

I am following this tutorial, and I'm trying to draw a thick line based on different coordinates.
https://github.com/leighhalliday/google-maps-threejs/blob/main/pages/car.js

My code stuck in here

trackRef.current.material.resolution.copy(
  overlayRef.current.getViewportSize()
);

because there's no 'resolution' in material.
My code for thick line is this:

const lineGeometry = new LineGeometry().setPositions(positions);
const lineMaterial = new THREE.LineBasicMaterial({
  color: 0xff0000,
  linewidth: 8,
});
const line = new Line2(lineGeometry, lineMaterial);

How do I access to material.resolution or does anyone know any other way to achieve the same thing?

答案1

得分: 0

你必须使用LineMaterial,而不是LineBasicMaterial。这两个类是两个不同的东西。只有LineMaterial可以用于渲染宽线条。请注意,你必须像这样单独导入这个材质:

import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
英文:

You have to use LineMaterial not LineBasicMaterial. Both classes are two different things. Only LineMaterial can be used for rendering wide lines. Notice that you have to import this material separately like so:

import { LineMaterial } from 'three/addons/lines/LineMaterial.js';

huangapple
  • 本文由 发表于 2023年5月29日 15:01:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355262.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定