首页 > 解决方案 > 创建自定义多面体几何的问题

问题描述

确实进行了调整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 };

标签: javascriptthree.jsgeometry

解决方案


推荐阅读