商域无疆 (http://blog.youkuaiyun.com/omni360/)
本文遵循“署名-非商业用途-保持一致”创作公用协议
转载请保留此句:商域无疆 - 本博客专注于 敏捷开发及移动和物联设备研究:数据可视化、GOLANG、Html5、WEBGL、THREE.JS,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
俺也是刚开始学,好多地儿肯定不对还请见谅.
以下代码是THREE.JS 源码文件中extras/geometries/ExtrudeGeometry.js文件的注释.
更多更新在 : https://github.com/omni360/three.js.sourcecode
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
*
* Creates extruded geometry from a path shape.
*
* parameters = {
*
* curveSegments: <int>, // number of points on the curves 曲线上的顶点数量
* steps: <int>, // number of points for z-side extrusions / used for subdividing segements of extrude spline too 步数,曲线拉伸的细分线段数
* amount: <int>, // Depth to extrude the shape 拉伸线段的厚度.
*
* bevelEnabled: <bool>, // turn on bevel 是否启用倒角
* bevelThickness: <float>, // how deep into the original shape bevel goes 倒角的厚度
* bevelSize: <float>, // how far from shape outline is bevel 从截面外轮廓倒角的尺寸.
* bevelSegments: <int>, // number of bevel layers 倒角部分的细分线段数.
*
* extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined) 截面拉伸的路径,3d的spline对象.
* frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals 包含三角形,法线,副法线数组.
*
* material: <int> // material index for front and back faces 正面和背面材质索引
* extrudeMaterial: <int> // material index for extrusion and beveled faces 拉伸体和斜面的材质索引
* uvGenerator: <Object> // object that provides UV generator functions UV坐标生成函数.
*
* }
**/
/*
///ExtrudeGeometry用来通过截面(参数shape)生成拉伸几何体.
*/
///<summary>ExtrudeGeometry</summary>
///<param name ="shapes" type="THREE.Shape">拉伸几何体截面</param>
///<param name ="options" type="Object">拉伸几何体参数选项</param>
THREE.ExtrudeGeometry = function ( shapes, options ) {
if ( typeof( shapes ) === "undefined" ) {
shapes = [];
return;
}
THREE.Geometry.call( this ); //调用Geometry()方法创建几何体,并将Geometry对象的方法供ExtrudeGeometry对象使用.
shapes = shapes instanceof Array ? shapes : [ shapes ];
this.addShapeList( shapes, options );
this.computeFaceNormals(); //计算三角面法线
// can't really use automatic vertex normals
// as then front and back sides get smoothed too
// should do separate smoothing just for sides
//this.computeVertexNormals();
//console.log( "took", ( Date.now() - startTime ) );
};
/*************************************************
****下面是ExtrudeGeometry对象的方法属性定义,继承自Geometry对象.
**************************************************/
THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
/*
///addShapeList方法将截面(参数shape)和参数选项,添加到shapes数组.
*/
///<summary>addShapeList</summary>
///<param name ="shapes" type="THREE.ShapeArray">拉伸几何体截面</param>
///<param name ="options" type="Object">拉伸几何体参数选项</param>
THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
var sl = shapes.length;
for ( var s = 0; s < sl; s ++ ) {
var shape = shapes[ s ];
this.addShape( shape, options );
}
};
/*
///addShape方法将截面(参数shape)和参数选项,获得构造几何体的截面.
*/
///<summary>addShape</summary>
///<param name ="shapes" type="THREE.ShapeArray">拉伸几何体截面</param>
///<param name ="options" type="Object">拉伸几何体参数选项</param>
///<returns type="Vector3Array">返回构造几何体的截面.</returns>
THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
var amount = options.amount !== undefined ? options.amount : 100; //拉伸线段的厚度
var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10 //倒角的厚度,默认初始化为6
var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8 //从截面外轮廓倒角的尺寸,默认初始化为bevelThickness - 2
var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3; //倒角部分的细分线段数,默认初始化为3
var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false //是否启用倒角,默认true
var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12; //曲线上的顶点数量
var steps = options.steps !== undefined ? options.steps : 1; /