Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在THREE.js中设置三点对象的顶点颜色_Three.js - Fatal编程技术网

如何在THREE.js中设置三点对象的顶点颜色

如何在THREE.js中设置三点对象的顶点颜色,three.js,Three.js,我正在尝试编写一个函数,从网格创建点云。我还想控制点云的每个顶点的颜色。到目前为止,我试图分配几何体的颜色,但颜色没有被更新 InteractablePointCloud_simug=function(object, editor){ var signals=editor.signals; var vertexSize=0.3; var pointMat= new THREE.PointsMaterial({size:vertexSize ,

我正在尝试编写一个函数,从网格创建点云。我还想控制点云的每个顶点的颜色。到目前为止,我试图分配几何体的颜色,但颜色没有被更新

InteractablePointCloud_simug=function(object, editor){

        var signals=editor.signals;

        var vertexSize=0.3;
        var pointMat= new THREE.PointsMaterial({size:vertexSize , vertexColors:THREE.VertexColors});

        var colors=[];
        var colorStep=0.1;

         for (var i = 0; i < object.geometry.vertices.length; i++) {
            colors.push(new 
            THREE.Color(colorStep*i,colorStep*i,colorStep*i));

         };

        //get points from mesh of original object
        var points=new THREE.Points(object.geometry,pointMat);

        //Update colors
        points.geometry.colors=colors;
        points.geometry.colorsNeedUpdate=true;


        updatePosition();

        //Add points object to scene
        editor.addNoneObjectMesh(points);
   }
interactiablepointcloud\u simug=函数(对象,编辑器){
var信号=编辑器信号;
var vertexSize=0.3;
var pointMat=new THREE.PointsMaterial({size:vertexSize,vertexColors:THREE.vertexColors});
var颜色=[];
var colorStep=0.1;
对于(var i=0;i
我认为这在其他显卡上可能是可行的,但我的显卡似乎不喜欢

理论上。。如果您的材质颜色为白色。。它应该乘以顶点颜色(基本上类似于使用顶点颜色),但是由于没有指定黑色作为颜色,所以这不是问题)

如果你的代码在你的计算机上不起作用(我的也不起作用),你将不得不去核。。。只需创建一个新的
selectedPointsGeometry
和一个新的
selectedPointsMesh

从原始顶点抓取两个顶点。。复制它们。。将它们放入
顶点
数组中。。并运行更新方法(每次都必须重新创建几何图形和网格..至少在我的电脑上,我尝试调用每个更新方法,并不得不求助于重新创建)

注意咖啡剧本
@anchor
是容器

  updateSelectedVertices: (vertices) ->
    if @selectedParticles
      @anchor.remove @selectedParticles

    @pointGeometry = new THREE.Geometry()

    @pointGeometry.vertices = vertices

    @selectedParticles = new (THREE.PointCloud)(
      @pointGeometry,
      @selectedPointMaterial
    )
    @pointGeometry.verticesNeedUpdate = true
    @pointGeometry.computeLineDistances()
    @selectedParticles.scale.copy @particles.scale
    @selectedParticles.sortParticles = true
    @anchor.add @selectedParticles
selectedPointMaterial
在别处定义。只需使用不同的颜色(和不同的尺寸)。。而不是非选定的点云

即。。对于未选定的点云,使用黑色和大小5;对于选定的点云,使用黄色和大小10

我的另一个网格称为
@particles
。。我只需要复制比例。(这是未选定的点云)

现在,我选择的点显示为黄色

我认为这在其他视频卡上可能是可行的,但我的似乎不喜欢

理论上。。如果您的材质颜色为白色。。它应该乘以顶点颜色(基本上类似于使用顶点颜色),但是由于没有指定黑色作为颜色,所以这不是问题)

如果你的代码在你的计算机上不起作用(我的也不起作用),你将不得不去核。。。只需创建一个新的
selectedPointsGeometry
和一个新的
selectedPointsMesh

从原始顶点抓取两个顶点。。复制它们。。将它们放入
顶点
数组中。。并运行更新方法(每次都必须重新创建几何图形和网格..至少在我的电脑上,我尝试调用每个更新方法,并不得不求助于重新创建)

注意咖啡剧本
@anchor
是容器

  updateSelectedVertices: (vertices) ->
    if @selectedParticles
      @anchor.remove @selectedParticles

    @pointGeometry = new THREE.Geometry()

    @pointGeometry.vertices = vertices

    @selectedParticles = new (THREE.PointCloud)(
      @pointGeometry,
      @selectedPointMaterial
    )
    @pointGeometry.verticesNeedUpdate = true
    @pointGeometry.computeLineDistances()
    @selectedParticles.scale.copy @particles.scale
    @selectedParticles.sortParticles = true
    @anchor.add @selectedParticles
selectedPointMaterial
在别处定义。只需使用不同的颜色(和不同的尺寸)。。而不是非选定的点云

即。。对于未选定的点云,使用黑色和大小5;对于选定的点云,使用黄色和大小10

我的另一个网格称为
@particles
。。我只需要复制比例。(这是未选定的点云)

现在,我选择的点显示为黄色

尝试新的三种颜色(r,g,b)
,其中r,g,b在[0,1]范围内。请参阅。我已经在使用新的THREE.Color()尝试
新的THREE.Color(r,g,b)
,其中r,g,b在[0,1]范围内。看,我已经在使用新的THREE.Color()