- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ThreeJS 创建点云。我想根据其位置为云中的每个点赋予特定的颜色。如何为几何中的每个顶点分配特定颜色并在必要时更改顶点的颜色?
geometry = new THREE.Geometry();
for (i = 0; i < particleCount; i++) {
var vertex = new THREE.Vector3();
vertex.x = Math.random() * 2000 - 1000;
vertex.y = Math.random() * 2000 - 1000;
vertex.z = Math.random() * 2000 - 1000;
geometry.vertices.push(vertex);
}
colors = [0xff0000, 0x0000FF, 0x00FF00, 0x000000]
size = 0.5
material = new THREE.PointsMaterial({
size: size,
color: colors[0]
});
particles = new THREE.Points(geometry, material);
scene.add(particles);
最佳答案
以 r125
开头, THREE.Geometry
已弃用,不再是核心的一部分。强烈建议使用 THREE.BufferGeometry
.
您可以通过添加一个包含顶点颜色的附加缓冲区属性来为每个顶点应用一种颜色。您还必须设置 Material 属性 vertexColors
至true
.
let camera, scene, renderer;
let points;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 5, 3500 );
camera.position.z = 2750;
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x050505 );
scene.fog = new THREE.Fog( 0x050505, 2000, 3500 );
//
const particles = 500000;
const geometry = new THREE.BufferGeometry();
const positions = [];
const colors = [];
const color = new THREE.Color();
const n = 1000, n2 = n / 2; // particles spread in the cube
for ( let i = 0; i < particles; i ++ ) {
// positions
const x = Math.random() * n - n2;
const y = Math.random() * n - n2;
const z = Math.random() * n - n2;
positions.push( x, y, z );
// colors
const vx = ( x / n ) + 0.5;
const vy = ( y / n ) + 0.5;
const vz = ( z / n ) + 0.5;
color.setRGB( vx, vy, vz );
colors.push( color.r, color.g, color.b );
}
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
//
const material = new THREE.PointsMaterial( { size: 15, vertexColors: true } );
points = new THREE.Points( geometry, material );
scene.add( points );
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//
window.addEventListener( 'resize', onWindowResize );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
const time = Date.now() * 0.001;
points.rotation.x = time * 0.25;
points.rotation.y = time * 0.5;
renderer.render( scene, camera );
}
body {
margin: 0;
}
<script src="https://cdn.jsdelivr.net/npm/three@0.125.2/build/three.js"></script>
关于javascript - 如何在 ThreeJS 中为每个点赋予自己的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66225871/
Solr中有什么方法可以给同义词赋予权重? (由 SynonymFilterFactory 生成) 问题的较长版本/一些背景: 我们希望为 SynonymFilterFactory 注入(inject
假设我有一个可以扩展的 A 类。在 A 类中,我有一个列表 List 。所以这个类将包含一个包含元素 A 的列表。现在,如果我将这个类 B 扩展为 A 的子类,我希望类 B 具有相同的成员 List
有没有办法让 SKNode 拥有自己的物理特性?我有一个 SKShapeNode 调用“backGround”,我将其用作大多数其他节点的父节点。我不断地将“背景”向左移动,给人一种玩家正在前进的错觉
我想观察一个由完全独立的代码修改的 ObservableList。我的问题是,我不仅希望在列表更改时调用 ListChangeListener(当我附加监听器时,列表可能已经包含元素),而且我还希望将
我正在尝试通过按最匹配的记录对记录进行排序来改进我的网站之一中的搜索功能。 我有以下 mysql 表。 调查回复 +--------+-------------+------------------+
我想给予 最高优先级.在我的示例中,我想要 的背景-要显示的元素,而不是为 指定的内容-元素。 h1{ background-color:blue1!important } 但它在下面的上下
我正在使用 SliverAppBar和 SliverListView在我的项目中。 我需要BorderRadius到我的 SliverList这是我的 SliverAppBar 的底部. 这是我需要的
我有它,这样当您(PaintBrush)完成时,一切都会清除并出现一个按钮。单击该按钮时,它开始二级,在这里它创建一个新的 Canvas 。我添加了一些代码,以便在单击按钮时删除旧 Canvas ,然
在下面的代码中,我分析给定的包以获取使用给定注释注释的所有类。 我想将它们及其注释(及其值)加载到 map 中。 package com.test @Named("valueToStock") pub
HTML: Div CSS: body{ width: 600px; height: 600px; background: red; }
我在我的图片库中应用了 jquery lighbox,但由于图像大小可变,灯箱大小不固定,因此以图像的原始大小打开,这反过来导致 biga 图像超出屏幕并显示浏览器中的水平滚动条。 因此,我正在寻找将
无论如何,包含文件是否可以在父范围内使用到它被调用的范围?以下示例经过简化,但完成相同的工作。 本质上,一个文件将被一个函数包含,但希望被包含文件的范围是调用包含它的函数的范围。 主.php: get
我有一个 html 页面,其中包含许多使用 a 标记的链接。我想在不同的选项卡中打开所有链接,而不是在所有标签中设置 target="_blank" ,有没有像下面的css那样做: a{target=
我正在使用 Zend_Navigation 并试图将它与 Zend_Acl 集成。导航中的每个页面都有一个 privilege 属性。我无法确定的是如何为单个页面定义多个权限。 用例:用于管理用户的页
所以,我的代码(Perl 脚本和 Perl 模块)位于这样的树中: trunk/ util/ process/ scripts/ 'util' 目录有,嗯,实用程序,'pr
这个问题在这里已经有了答案: How to clone a Date object? (8 个答案) 关闭 4 年前。 我正在处理日期,我的代码如下所示: (currentDate 只是要记住的实际
我刚开始使用 Crashlytics。我已经开始探索使用日志记录并创建了一个示例 ios 项目来测试它。我可以看到 CLSLogv 命令的第一个参数,但缺少第二个参数 例子:CLSLogv("Butt
我是 asp.net 的新手,我想为链接标签添加样式。我的代码如下: Guest .userlabel { display:inline-block; text-decoration:
我有一个页面,其中我使用 HTML 表格中的 RadiobuttonList。我已经为 table 和 td 提供了 CSS 样式。我还为 RadioButtonList 提供了 CSS 样式,但它没
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我是一名优秀的程序员,十分优秀!