本文整理汇总了TypeScript中THREE.SphereGeometry类的典型用法代码示例。如果您正苦于以下问题:TypeScript SphereGeometry类的具体用法?TypeScript SphereGeometry怎么用?TypeScript SphereGeometry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SphereGeometry类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildPommel
/**
* Creates a spherical pommel and merges it with the swords geometry.
* Given: the geometry of the sword, and some parameters about
* the geometry of the sword
* Returns: The Sword
*/
buildPommel(template : SwordTemplate, genParams : GenerationParameters, sword: Sword, numHands: number = 1, pommelBladeWidthRatio = 0.50) : Sword {
var pommelRadius = genParams.bladeThickness;
var pommelGeometry = new THREE.SphereGeometry(pommelRadius, 5, 5);
var handleLength = 0.4 * numHands;
// Translates the pommel to fall below the handle
pommelGeometry.translate(0,-handleLength,0);
// Convert the box to a buffer geometry
var pommelBufferGeometry = new THREE.BufferGeometry().fromGeometry(pommelGeometry);
// Number of vertices in the model prior to appending this geometry
var priorNumVertices = sword.geometryData.vertices.length / 3;
// Append the vertices to the swords vertex array and add their indices to the vertex indices array
var vertices = pommelBufferGeometry.getAttribute("position");
// Loop through all of the position attributes and add the XYZ values to the swords geometry
for (var i = 0; i < vertices.count; i++) {
sword.geometryData.addVertex(vertices.getX(i), vertices.getY(i), vertices.getZ(i));
}
// Append the vertices to the swords vertex array and add their indices to the vertex indices array
var normals = pommelBufferGeometry.getAttribute("normal");
// Loop through all of the position attributes and add the XYZ values to the swords geometry
for (var i = 0; i < vertices.count; i++) {
sword.geometryData.addNormal(normals.getX(i), normals.getY(i), normals.getZ(i));
}
// Add a color for each vertex (Gold)
for (var i = 0; i < vertices.count; i++) {
sword.geometryData.addColor(0.9, 0.8, 0.35);
}
var triangles = pommelBufferGeometry.getIndex();
if (triangles != undefined) {
// Loop through all of the triangles and add the values to the swords geometry
for (var i = 0; i < triangles.count; i++) {
sword.geometryData.addTriangle(triangles.getX(i), triangles.getY(i), triangles.getZ(i));
}
} else {
// We need to add index values based on the vertices being added
Assert.equal(vertices.count % 3, 0, "ERROR:: Verices are not organized into triangles");
for (var i = 0; i < vertices.count;) {
sword.geometryData.addTriangle(priorNumVertices + i, priorNumVertices + i + 1, priorNumVertices + i + 2);
i += 3;
}
}
return sword;
}
示例2: _getFlatImageSphereGeo
private _getFlatImageSphereGeo(transform: Transform): THREE.Geometry {
let gpano: IGPano = transform.gpano;
let phiStart: number = 2 * Math.PI * gpano.CroppedAreaLeftPixels / gpano.FullPanoWidthPixels;
let phiLength: number = 2 * Math.PI * gpano.CroppedAreaImageWidthPixels / gpano.FullPanoWidthPixels;
let thetaStart: number = Math.PI * gpano.CroppedAreaTopPixels / gpano.FullPanoHeightPixels;
let thetaLength: number = Math.PI * gpano.CroppedAreaImageHeightPixels / gpano.FullPanoHeightPixels;
let geometry: THREE.SphereGeometry = new THREE.SphereGeometry(
this._imageSphereRadius,
20,
40,
phiStart - Math.PI / 2,
phiLength,
thetaStart,
thetaLength
);
geometry.applyMatrix(new THREE.Matrix4().getInverse(transform.rt));
return geometry;
}
示例3: constructor
constructor(position: Vector3, attr: {
color: Color;
texture: Texture;
displayHalo: boolean;
applyDistortion: boolean;
size: number;
}) {
this.size = attr.size;
this.position = position;
var starMaterial: Material;
attr.texture.wrapS = attr.texture.wrapT = RepeatWrapping;
if (attr.applyDistortion) {
this.starUniforms = {
baseTexture: { type: "t", value: attr.texture },
baseSpeed: { type: "f", value: 0.02 },
repeatS: { type: "f", value: 1.0 },
repeatT: { type: "f", value: 1.0 },
noiseTexture: { type: "t", value: noiseTexture },
noiseScale: { type: "f", value: 0.5 },
blendTexture: { type: "t", value: attr.texture },
blendSpeed: { type: "f", value: 0.01 },
blendOffset: { type: "f", value: 0.25 },
bumpTexture: { type: "t", value: noiseTexture },
bumpSpeed: { type: "f", value: 0.15 },
bumpScale: { type: "f", value: 100.0 },
alpha: { type: "f", value: 1.0 },
time: { type: "f", value: 1.0 }
};
starMaterial = new ShaderMaterial({
uniforms: this.starUniforms,
vertexShader: starVertex,
fragmentShader: starFragment
});
} else {
starMaterial = new MeshBasicMaterial({
map: attr.texture
});
}
var shiny = new Mesh(new SphereGeometry(attr.size, 64, 64), starMaterial);
shiny.position.copy(position);
if (attr.displayHalo) {
this.uniform = {
"c": { type: "f", value: 0.5 },
"p": { type: "f", value: 4 },
glowColor: { type: "c", value: attr.color },
viewVector: { type: "v3", value: new Vector3() }
};
var customMaterial = new ShaderMaterial({
uniforms: this.uniform,
vertexShader: vertex,
fragmentShader: fragment,
side: FrontSide,
blending: AdditiveBlending,
transparent: true
});
var ballGeometry = new SphereGeometry(attr.size, 64, 64);
ballGeometry.computeFaceNormals();
ballGeometry.computeVertexNormals();
var halo = new Mesh(ballGeometry, customMaterial);
halo.scale.multiplyScalar(haloScale);
halo.position.copy(position);
this.halo = halo;
}
this.mesh = shiny;
var priorRotationMatrix = new Matrix4();
var axis = new Vector3(
Math.random() - 0.5,
0,
Math.random() - 0.5
);
priorRotationMatrix.makeRotationAxis(axis.normalize(), Math.random());
this.mesh.matrix.multiply(priorRotationMatrix);
this.rotationMatrix = new Matrix4();
this.rotationMatrix.makeRotationAxis(new Vector3(0, 1, 0), Math.random() * 0.02 + 0.01)
this.mesh.rotation.setFromRotationMatrix(this.mesh.matrix);
}