英文:
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';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论