创建自定义多面体几何的问题

时间:2018-12-18 18:33:33

标签: javascript three.js geometry

请调整DodecahedronGeometry使其成为菱形十二面体,将所有新的顶点和与法线连接的面朝外 当我尝试将其加载到three.js时不起作用。

有关如何向three.js库添加新形状的任何提示或技巧。

/**
* @author Abe Pazos / https://hamoid.com
* @author Mugen87 / https://github.com/Mugen87
*/

import { Geometry } from '../core/Geometry.js';
import { PolyhedronBufferGeometry } from './PolyhedronGeometry.js';

// RhombicDodecahedronGeometry

function RhombicDodecahedronGeometry( radius, detail ) {

  Geometry.call( this );

  this.type = 'RhombicDodecahedronGeometry';

  this.parameters = {
    radius: radius,
    detail: detail
  };

  this.fromBufferGeometry( new RhombicDodecahedronBufferGeometry( radius, detail ) );
  this.mergeVertices();

}

RhombicDodecahedronGeometry.prototype = Object.create( Geometry.prototype );
RhombicDodecahedronGeometry.prototype.constructor = RhombicDodecahedronGeometry;

// DodecahedronBufferGeometry

function RhombicDodecahedronBufferGeometry( radius, detail ) {

  var vertices = [

    // (±1, ±1, ±1)
    - 1, - 1, - 1,  1, - 1, - 1,
    1, - 1, 1,  - 1, - 1, 1,
    - 1, 1, 1,  - 1, 1, 1,
    1, 1, 1,  1, 1, - 1,

    0, 2, 0,  0, - 2, 0,
    0, 0, - 2,  0, 0, 2,
    2, 0, 0,  - 2, 0, 0

  ];

  var indices = [

    0, 3, 13,   9, 3, 0,
    0, 13, 4,  10, 0, 4,
    9, 0, 1,  1, 0, 10,
    7, 10, 4,  4, 8, 7,
    4, 13, 5,  8, 4, 5,
    5, 13, 3,  5, 3, 11,
    3, 2, 11,  3, 9, 2,
    5, 11, 6,  8, 5, 6,
    6, 11, 2,  6, 2, 12,
    12, 7, 6,  7, 8, 6,
    12, 1, 7,  7, 1, 10,
    1, 12, 2,  2, 9, 1

  ];

  PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );

  this.type = 'RhombicDodecahedronBufferGeometry';

  this.parameters = {
    radius: radius,
    detail: detail
  };

}

RhombicDodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
RhombicDodecahedronBufferGeometry.prototype.constructor = RhombicDodecahedronBufferGeometry;


export { RhombicDodecahedronGeometry, RhombicDodecahedronBufferGeometry };

1 个答案:

答案 0 :(得分:0)

编辑顶点:

 var vertices = [
    -1, -1, -1,    1, -1, -1,
     1, -1,  1,   -1, -1,  1,
    -1,  1, -1,   -1,  1,  1, // error here
     1,  1,  1,    1,  1, -1,

    0, 2,  0,    0, -2, 0,
    0, 0, -2,    0,  0, 2,
    2, 0,  0,   -2,  0, 0
];