|
@@ -1355,61 +1355,61 @@
|
|
}
|
|
}
|
|
|
|
|
|
// setup tube creation parameters
|
|
// setup tube creation parameters
|
|
- var path = [
|
|
|
|
- new Vector3(0, -height/2, 0),
|
|
|
|
- new Vector3(0, height/2, 0),
|
|
|
|
- ];
|
|
|
|
-
|
|
|
|
- var radiusFunction = function (i, distance) {
|
|
|
|
- return (diameterBottom + (diameterTop - diameterBottom) * distance / height)/2;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // create tube without caps
|
|
|
|
- var cylinder = Mesh.CreateTube(name, path, 1.0, tessellation, radiusFunction, Mesh.NO_CAP, scene, updatable, sideOrientation);
|
|
|
|
-
|
|
|
|
- // extract geometry data to add caps
|
|
|
|
- var geometry_data = VertexData.ExtractFromMesh(cylinder);
|
|
|
|
-
|
|
|
|
- var createCylinderCap = function (isTop) {
|
|
|
|
- var radius = isTop ? diameterTop/2 : diameterBottom/2;
|
|
|
|
- if (radius === 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- var vbase = geometry_data.positions.length / 3;
|
|
|
|
- var offset = new Vector3(0, isTop ? height / 2 : -height / 2, 0);
|
|
|
|
- var textureScale = new Vector2(0.5, 0.5);
|
|
|
|
- // Positions, normals & uvs
|
|
|
|
- var angle;
|
|
|
|
- for (var i = 0; i < tessellation; i++) {
|
|
|
|
- angle = Math.PI * 2 * i / tessellation;
|
|
|
|
- var circleVector = new Vector3(Math.cos(angle), 0, Math.sin(angle));
|
|
|
|
- var position = circleVector.scale(radius).add(offset);
|
|
|
|
- var textureCoordinate = new Vector2(circleVector.x * textureScale.x + 0.5, circleVector.z * textureScale.y + 0.5);
|
|
|
|
- geometry_data.positions.push(position.x, position.y, position.z);
|
|
|
|
- geometry_data.normals.push(0, 1, 0);
|
|
|
|
- geometry_data.uvs.push(textureCoordinate.x, textureCoordinate.y);
|
|
|
|
- }
|
|
|
|
- // Indices
|
|
|
|
- for (i = 0; i < tessellation - 2; i++) {
|
|
|
|
- if (!isTop) {
|
|
|
|
- geometry_data.indices.push(vbase);
|
|
|
|
- geometry_data.indices.push(vbase + (i + 2) % tessellation);
|
|
|
|
- geometry_data.indices.push(vbase + (i + 1) % tessellation);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- geometry_data.indices.push(vbase);
|
|
|
|
- geometry_data.indices.push(vbase + (i + 1) % tessellation);
|
|
|
|
- geometry_data.indices.push(vbase + (i + 2) % tessellation);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // add caps to geometry and apply to mesh
|
|
|
|
- createCylinderCap(true);
|
|
|
|
- createCylinderCap(false);
|
|
|
|
- geometry_data.applyToMesh(cylinder);
|
|
|
|
-
|
|
|
|
- return cylinder;
|
|
|
|
|
|
+ var path = [
|
|
|
|
+ new Vector3(0, -height/2, 0),
|
|
|
|
+ new Vector3(0, height/2, 0),
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ var radiusFunction = function (i, distance) {
|
|
|
|
+ return (diameterBottom + (diameterTop - diameterBottom) * distance / height)/2;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // create tube without caps
|
|
|
|
+ var cylinder = Mesh.CreateTube(name, path, 1.0, tessellation, radiusFunction, Mesh.NO_CAP, scene, updatable, sideOrientation);
|
|
|
|
+
|
|
|
|
+ // extract geometry data to add caps
|
|
|
|
+ var geometry_data = VertexData.ExtractFromMesh(cylinder);
|
|
|
|
+
|
|
|
|
+ var createCylinderCap = function (isTop) {
|
|
|
|
+ var radius = isTop ? diameterTop/2 : diameterBottom/2;
|
|
|
|
+ if (radius === 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ var vbase = geometry_data.positions.length / 3;
|
|
|
|
+ var offset = new Vector3(0, isTop ? height / 2 : -height / 2, 0);
|
|
|
|
+ var textureScale = new Vector2(0.5, 0.5);
|
|
|
|
+ // Positions, normals & uvs
|
|
|
|
+ var angle;
|
|
|
|
+ for (var i = 0; i < tessellation; i++) {
|
|
|
|
+ angle = Math.PI * 2 * i / tessellation;
|
|
|
|
+ var circleVector = new Vector3(Math.cos(angle), 0, Math.sin(angle));
|
|
|
|
+ var position = circleVector.scale(radius).add(offset);
|
|
|
|
+ var textureCoordinate = new Vector2(circleVector.x * textureScale.x + 0.5, circleVector.z * textureScale.y + 0.5);
|
|
|
|
+ geometry_data.positions.push(position.x, position.y, position.z);
|
|
|
|
+ geometry_data.normals.push(0, 1, 0);
|
|
|
|
+ geometry_data.uvs.push(textureCoordinate.x, textureCoordinate.y);
|
|
|
|
+ }
|
|
|
|
+ // Indices
|
|
|
|
+ for (i = 0; i < tessellation - 2; i++) {
|
|
|
|
+ if (!isTop) {
|
|
|
|
+ geometry_data.indices.push(vbase);
|
|
|
|
+ geometry_data.indices.push(vbase + (i + 2) % tessellation);
|
|
|
|
+ geometry_data.indices.push(vbase + (i + 1) % tessellation);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ geometry_data.indices.push(vbase);
|
|
|
|
+ geometry_data.indices.push(vbase + (i + 1) % tessellation);
|
|
|
|
+ geometry_data.indices.push(vbase + (i + 2) % tessellation);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // add caps to geometry and apply to mesh
|
|
|
|
+ createCylinderCap(true);
|
|
|
|
+ createCylinderCap(false);
|
|
|
|
+ geometry_data.applyToMesh(cylinder);
|
|
|
|
+
|
|
|
|
+ return cylinder;
|
|
}
|
|
}
|
|
|
|
|
|
// Torus (Code from SharpDX.org)
|
|
// Torus (Code from SharpDX.org)
|