MCPcopy Create free account
hub / github.com/microsoft/SandDance / tesselateSphere

Function tesselateSphere

docs/app/js/sanddance-app.js:78978–79054  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

78976 return SphereGeometry1;
78977}((0, _geometryDefault.default));
78978function tesselateSphere(props) {
78979 var _props$nlat = props.nlat, nlat = _props$nlat === void 0 ? 10 : _props$nlat, _props$nlong = props.nlong, nlong = _props$nlong === void 0 ? 10 : _props$nlong;
78980 var _props$radius = props.radius, radius = _props$radius === void 0 ? 1 : _props$radius;
78981 var startLat = 0;
78982 var endLat = Math.PI;
78983 var latRange = endLat - startLat;
78984 var startLong = 0;
78985 var endLong = 2 * Math.PI;
78986 var longRange = endLong - startLong;
78987 var numVertices = (nlat + 1) * (nlong + 1);
78988 if (typeof radius === "number") {
78989 var value = radius;
78990 radius = function radius(n1, n2, n3, u, v) {
78991 return value;
78992 };
78993 }
78994 var positions = new Float32Array(numVertices * 3);
78995 var normals = new Float32Array(numVertices * 3);
78996 var texCoords = new Float32Array(numVertices * 2);
78997 var IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;
78998 var indices = new IndexType(nlat * nlong * 6);
78999 for(var y = 0; y <= nlat; y++)for(var x = 0; x <= nlong; x++){
79000 var u = x / nlong;
79001 var v = y / nlat;
79002 var index = x + y * (nlong + 1);
79003 var i2 = index * 2;
79004 var i3 = index * 3;
79005 var theta = longRange * u;
79006 var phi = latRange * v;
79007 var sinTheta = Math.sin(theta);
79008 var cosTheta = Math.cos(theta);
79009 var sinPhi = Math.sin(phi);
79010 var cosPhi = Math.cos(phi);
79011 var ux = cosTheta * sinPhi;
79012 var uy = cosPhi;
79013 var uz = sinTheta * sinPhi;
79014 var r = radius(ux, uy, uz, u, v);
79015 positions[i3 + 0] = r * ux;
79016 positions[i3 + 1] = r * uy;
79017 positions[i3 + 2] = r * uz;
79018 normals[i3 + 0] = ux;
79019 normals[i3 + 1] = uy;
79020 normals[i3 + 2] = uz;
79021 texCoords[i2 + 0] = u;
79022 texCoords[i2 + 1] = 1 - v;
79023 }
79024 var numVertsAround = nlong + 1;
79025 for(var _x = 0; _x < nlong; _x++)for(var _y = 0; _y < nlat; _y++){
79026 var _index = (_x * nlat + _y) * 6;
79027 indices[_index + 0] = _y * numVertsAround + _x;
79028 indices[_index + 1] = _y * numVertsAround + _x + 1;
79029 indices[_index + 2] = (_y + 1) * numVertsAround + _x;
79030 indices[_index + 3] = (_y + 1) * numVertsAround + _x;
79031 indices[_index + 4] = _y * numVertsAround + _x + 1;
79032 indices[_index + 5] = (_y + 1) * numVertsAround + _x + 1;
79033 }
79034 return {
79035 indices: {

Callers 1

SphereGeometry1Function · 0.70

Calls 1

radiusFunction · 0.70

Tested by

no test coverage detected