@antv/g-plugin-3d
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,2 +0,3 @@ | ||
import { Geometry } from '@antv/g-plugin-webgl-renderer'; | ||
import { Mesh } from '@antv/g-plugin-webgl-renderer'; | ||
import { ProceduralGeometry } from './ProceduralGeometry'; | ||
export interface CubeGeometryProps { | ||
@@ -10,8 +11,11 @@ height: number; | ||
} | ||
export declare class CubeGeometry extends Geometry { | ||
private props; | ||
constructor(props: CubeGeometryProps); | ||
init(): void; | ||
updateAttribute<Key extends keyof CubeGeometryProps>(name: Key, value: CubeGeometryProps[Key], index: number): void; | ||
private buildAttributes; | ||
export declare class CubeGeometry extends ProceduralGeometry<CubeGeometryProps> { | ||
createTopology(meshes: Mesh<CubeGeometryProps>[]): { | ||
indices: number[]; | ||
positions: number[]; | ||
normals: number[]; | ||
uvs: number[]; | ||
uvs1: number[]; | ||
vertexCountPerInstance: number; | ||
}; | ||
} |
@@ -0,1 +1,4 @@ | ||
export * from './ProceduralGeometry'; | ||
export * from './CubeGeometry'; | ||
export * from './SphereGeometry'; | ||
export * from './TorusGeometry'; |
/// <reference path="../../../../../../../../Users/panyuqi/Documents/webgl/g/packages/g-plugin-3d/src/glsl.d.ts" /> | ||
import { RendererPlugin } from '@antv/g'; | ||
import { Syringe } from 'mana-syringe'; | ||
import { Mesh } from '@antv/g-plugin-webgl-renderer'; | ||
import { Mesh, Texture2D, Sampler, FogType } from '@antv/g-plugin-webgl-renderer'; | ||
export * from './geometries'; | ||
export * from './materials'; | ||
export { Mesh }; | ||
export * from './lights'; | ||
export { Mesh, Texture2D, Sampler, FogType }; | ||
export declare const containerModule: import("mana-syringe").SyringeModule; | ||
@@ -9,0 +10,0 @@ export declare class Plugin implements RendererPlugin { |
import { Module } from 'mana-syringe'; | ||
import { Format, Geometry, Material } from '@antv/g-plugin-webgl-renderer'; | ||
export { Mesh } from '@antv/g-plugin-webgl-renderer'; | ||
import { Format, BufferGeometry, Material, Light } from '@antv/g-plugin-webgl-renderer'; | ||
export { FogType, Mesh, Sampler, Texture2D } from '@antv/g-plugin-webgl-renderer'; | ||
@@ -124,2 +124,38 @@ function ownKeys(object, enumerableOnly) { | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -162,2 +198,32 @@ if (self === void 0) { | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get; | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
/** | ||
@@ -180,2 +246,209 @@ * Common utilities | ||
/** | ||
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied. | ||
* @module mat4 | ||
*/ | ||
/** | ||
* Creates a new identity mat4 | ||
* | ||
* @returns {mat4} a new 4x4 matrix | ||
*/ | ||
function create() { | ||
var out = new ARRAY_TYPE(16); | ||
if (ARRAY_TYPE != Float32Array) { | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 0; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 0; | ||
out[9] = 0; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
} | ||
out[0] = 1; | ||
out[5] = 1; | ||
out[10] = 1; | ||
out[15] = 1; | ||
return out; | ||
} | ||
/** | ||
* Copy the values from one mat4 to another | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function copy(out, a) { | ||
out[0] = a[0]; | ||
out[1] = a[1]; | ||
out[2] = a[2]; | ||
out[3] = a[3]; | ||
out[4] = a[4]; | ||
out[5] = a[5]; | ||
out[6] = a[6]; | ||
out[7] = a[7]; | ||
out[8] = a[8]; | ||
out[9] = a[9]; | ||
out[10] = a[10]; | ||
out[11] = a[11]; | ||
out[12] = a[12]; | ||
out[13] = a[13]; | ||
out[14] = a[14]; | ||
out[15] = a[15]; | ||
return out; | ||
} | ||
/** | ||
* Transpose the values of a mat4 | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function transpose(out, a) { | ||
// If we are transposing ourselves we can skip a few steps but have to cache some values | ||
if (out === a) { | ||
var a01 = a[1], | ||
a02 = a[2], | ||
a03 = a[3]; | ||
var a12 = a[6], | ||
a13 = a[7]; | ||
var a23 = a[11]; | ||
out[1] = a[4]; | ||
out[2] = a[8]; | ||
out[3] = a[12]; | ||
out[4] = a01; | ||
out[6] = a[9]; | ||
out[7] = a[13]; | ||
out[8] = a02; | ||
out[9] = a12; | ||
out[11] = a[14]; | ||
out[12] = a03; | ||
out[13] = a13; | ||
out[14] = a23; | ||
} else { | ||
out[0] = a[0]; | ||
out[1] = a[4]; | ||
out[2] = a[8]; | ||
out[3] = a[12]; | ||
out[4] = a[1]; | ||
out[5] = a[5]; | ||
out[6] = a[9]; | ||
out[7] = a[13]; | ||
out[8] = a[2]; | ||
out[9] = a[6]; | ||
out[10] = a[10]; | ||
out[11] = a[14]; | ||
out[12] = a[3]; | ||
out[13] = a[7]; | ||
out[14] = a[11]; | ||
out[15] = a[15]; | ||
} | ||
return out; | ||
} | ||
/** | ||
* Inverts a mat4 | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function invert(out, a) { | ||
var a00 = a[0], | ||
a01 = a[1], | ||
a02 = a[2], | ||
a03 = a[3]; | ||
var a10 = a[4], | ||
a11 = a[5], | ||
a12 = a[6], | ||
a13 = a[7]; | ||
var a20 = a[8], | ||
a21 = a[9], | ||
a22 = a[10], | ||
a23 = a[11]; | ||
var a30 = a[12], | ||
a31 = a[13], | ||
a32 = a[14], | ||
a33 = a[15]; | ||
var b00 = a00 * a11 - a01 * a10; | ||
var b01 = a00 * a12 - a02 * a10; | ||
var b02 = a00 * a13 - a03 * a10; | ||
var b03 = a01 * a12 - a02 * a11; | ||
var b04 = a01 * a13 - a03 * a11; | ||
var b05 = a02 * a13 - a03 * a12; | ||
var b06 = a20 * a31 - a21 * a30; | ||
var b07 = a20 * a32 - a22 * a30; | ||
var b08 = a20 * a33 - a23 * a30; | ||
var b09 = a21 * a32 - a22 * a31; | ||
var b10 = a21 * a33 - a23 * a31; | ||
var b11 = a22 * a33 - a23 * a32; // Calculate the determinant | ||
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; | ||
if (!det) { | ||
return null; | ||
} | ||
det = 1.0 / det; | ||
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; | ||
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; | ||
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; | ||
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; | ||
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; | ||
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; | ||
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; | ||
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; | ||
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; | ||
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; | ||
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; | ||
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; | ||
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; | ||
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; | ||
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; | ||
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; | ||
return out; | ||
} | ||
/** | ||
* Creates a matrix from a vector scaling | ||
* This is equivalent to (but much faster than): | ||
* | ||
* mat4.identity(dest); | ||
* mat4.scale(dest, dest, vec); | ||
* | ||
* @param {mat4} out mat4 receiving operation result | ||
* @param {ReadonlyVec3} v Scaling vector | ||
* @returns {mat4} out | ||
*/ | ||
function fromScaling(out, v) { | ||
out[0] = v[0]; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 0; | ||
out[5] = v[1]; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 0; | ||
out[9] = 0; | ||
out[10] = v[2]; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
out[15] = 1; | ||
return out; | ||
} | ||
/** | ||
* 3 Dimensional Vector | ||
@@ -191,3 +464,3 @@ * @module vec3 | ||
function create() { | ||
function create$1() { | ||
var out = new ARRAY_TYPE(3); | ||
@@ -288,3 +561,3 @@ | ||
var forEach = function () { | ||
var vec = create(); | ||
var vec = create$1(); | ||
return function (a, stride, offset, count, fn, arg) { | ||
@@ -321,38 +594,165 @@ var i, l; | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeGeometry = /*#__PURE__*/function (_Geometry) { | ||
_inherits(CubeGeometry, _Geometry); | ||
/** | ||
* 4 Dimensional Vector | ||
* @module vec4 | ||
*/ | ||
var _super = _createSuper(CubeGeometry); | ||
/** | ||
* Creates a new, empty vec4 | ||
* | ||
* @returns {vec4} a new 4D vector | ||
*/ | ||
function CubeGeometry(props) { | ||
var _this; | ||
function create$2() { | ||
var out = new ARRAY_TYPE(4); | ||
_classCallCheck(this, CubeGeometry); | ||
if (ARRAY_TYPE != Float32Array) { | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
} | ||
_this = _super.call(this); | ||
_this.props = void 0; | ||
_this.props = _objectSpread2(_objectSpread2({}, props), {}, { | ||
// defaults | ||
widthSegments: 1, | ||
heightSegments: 1, | ||
depthSegments: 1 | ||
}); | ||
return _this; | ||
return out; | ||
} | ||
/** | ||
* Transforms the vec4 with a mat4. | ||
* | ||
* @param {vec4} out the receiving vector | ||
* @param {ReadonlyVec4} a the vector to transform | ||
* @param {ReadonlyMat4} m matrix to transform with | ||
* @returns {vec4} out | ||
*/ | ||
function transformMat4(out, a, m) { | ||
var x = a[0], | ||
y = a[1], | ||
z = a[2], | ||
w = a[3]; | ||
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; | ||
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; | ||
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; | ||
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; | ||
return out; | ||
} | ||
/** | ||
* Perform some operation over an array of vec4s. | ||
* | ||
* @param {Array} a the array of vectors to iterate over | ||
* @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed | ||
* @param {Number} offset Number of elements to skip at the beginning of the array | ||
* @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array | ||
* @param {Function} fn Function to call for each vector in the array | ||
* @param {Object} [arg] additional argument to pass to fn | ||
* @returns {Array} a | ||
* @function | ||
*/ | ||
var forEach$1 = function () { | ||
var vec = create$2(); | ||
return function (a, stride, offset, count, fn, arg) { | ||
var i, l; | ||
if (!stride) { | ||
stride = 4; | ||
} | ||
if (!offset) { | ||
offset = 0; | ||
} | ||
if (count) { | ||
l = Math.min(count * stride + offset, a.length); | ||
} else { | ||
l = a.length; | ||
} | ||
for (i = offset; i < l; i += stride) { | ||
vec[0] = a[i]; | ||
vec[1] = a[i + 1]; | ||
vec[2] = a[i + 2]; | ||
vec[3] = a[i + 3]; | ||
fn(vec, vec, arg); | ||
a[i] = vec[0]; | ||
a[i + 1] = vec[1]; | ||
a[i + 2] = vec[2]; | ||
a[i + 3] = vec[3]; | ||
} | ||
return a; | ||
}; | ||
}(); | ||
var ProceduralGeometryAttributeLocation; | ||
(function (ProceduralGeometryAttributeLocation) { | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["POSITION"] = 1] = "POSITION"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["NORMAL"] = 2] = "NORMAL"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["UV"] = 3] = "UV"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["MAX"] = 4] = "MAX"; | ||
})(ProceduralGeometryAttributeLocation || (ProceduralGeometryAttributeLocation = {})); | ||
var ProceduralGeometry = /*#__PURE__*/function (_BufferGeometry) { | ||
_inherits(ProceduralGeometry, _BufferGeometry); | ||
var _super = _createSuper(ProceduralGeometry); | ||
function ProceduralGeometry() { | ||
_classCallCheck(this, ProceduralGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(CubeGeometry, [{ | ||
key: "init", | ||
value: function init() { | ||
var _this$buildAttributes = this.buildAttributes([this.props]), | ||
indices = _this$buildAttributes.indices, | ||
positions = _this$buildAttributes.positions, | ||
normals = _this$buildAttributes.normals, | ||
uvs = _this$buildAttributes.uvs; | ||
_createClass(ProceduralGeometry, [{ | ||
key: "applyMat4", | ||
value: function applyMat4(mat) { | ||
var positions = this.vertexBuffers[ProceduralGeometryAttributeLocation.POSITION]; | ||
var v = create$2(); | ||
for (var i = 0; i < positions.byteLength / 4; i += 3) { | ||
v[0] = positions[i]; | ||
v[1] = positions[i + 1]; | ||
v[2] = positions[i + 2]; | ||
v[3] = 1; | ||
transformMat4(v, v, mat); | ||
positions[i] = v[0]; | ||
positions[i + 1] = v[1]; | ||
positions[i + 2] = v[2]; | ||
} | ||
var normals = this.vertexBuffers[ProceduralGeometryAttributeLocation.NORMAL]; | ||
var normalMatrix = copy(create(), mat); | ||
invert(normalMatrix, normalMatrix); | ||
transpose(normalMatrix, normalMatrix); | ||
for (var _i = 0; _i < normals.byteLength / 4; _i += 3) { | ||
v[0] = normals[_i]; | ||
v[1] = normals[_i + 1]; | ||
v[2] = normals[_i + 2]; | ||
v[3] = 1; | ||
transformMat4(v, v, normalMatrix); | ||
normals[_i] = v[0]; | ||
normals[_i + 1] = v[1]; | ||
normals[_i + 2] = v[2]; | ||
} // transform tangent | ||
} | ||
}, { | ||
key: "getBoundingBox", | ||
value: function getBoundingBox() {// 根据 ProceduralGeometryAttributeLocation.POSITION 计算 | ||
} | ||
}, { | ||
key: "build", | ||
value: function build(meshes) { | ||
var _this$createTopology = this.createTopology(meshes), | ||
indices = _this$createTopology.indices, | ||
positions = _this$createTopology.positions, | ||
normals = _this$createTopology.normals, | ||
uvs = _this$createTopology.uvs, | ||
vertexCountPerInstance = _this$createTopology.vertexCountPerInstance; | ||
this.setIndices(new Uint32Array(indices)); | ||
this.vertexCount = 36; | ||
this.vertexCount = vertexCountPerInstance; | ||
this.setVertexBuffer({ | ||
bufferIndex: 1, | ||
bufferIndex: ProceduralGeometryAttributeLocation.POSITION, | ||
byteStride: 4 * 3, | ||
@@ -370,3 +770,3 @@ frequency: 1 | ||
this.setVertexBuffer({ | ||
bufferIndex: 2, | ||
bufferIndex: ProceduralGeometryAttributeLocation.NORMAL, | ||
byteStride: 4 * 3, | ||
@@ -384,3 +784,3 @@ frequency: 1 | ||
this.setVertexBuffer({ | ||
bufferIndex: 3, | ||
bufferIndex: ProceduralGeometryAttributeLocation.UV, | ||
byteStride: 4 * 2, | ||
@@ -396,23 +796,37 @@ frequency: 1 | ||
data: Float32Array.from(uvs) | ||
}); | ||
}); // flip Y | ||
this.applyMat4(fromScaling(create(), fromValues(1, -1, 1))); | ||
} | ||
}, { | ||
key: "updateAttribute", | ||
value: function updateAttribute(name, value, index) { | ||
if (name === 'width' || name === 'height' || name === 'depth') { | ||
var _this$buildAttributes2 = this.buildAttributes([this.props]), | ||
positions = _this$buildAttributes2.positions; | ||
}]); | ||
this.updateVertexBuffer(1, 10, index, new Uint8Array(new Float32Array(positions).buffer)); | ||
} | ||
} | ||
}, { | ||
key: "buildAttributes", | ||
value: function buildAttributes(propsList) { | ||
return ProceduralGeometry; | ||
}(BufferGeometry); | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(CubeGeometry, _ProceduralGeometry); | ||
var _super = _createSuper(CubeGeometry); | ||
function CubeGeometry() { | ||
_classCallCheck(this, CubeGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(CubeGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var uvs1All = []; | ||
var indicesAll = []; | ||
var indicesStart = 0; | ||
propsList.forEach(function (props) { | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$widthSegments = props.widthSegments, | ||
@@ -437,5 +851,13 @@ widthSegments = _props$widthSegments === void 0 ? 1 : _props$widthSegments, | ||
var corners = [fromValues(-hex, -hey, hez), fromValues(hex, -hey, hez), fromValues(hex, hey, hez), fromValues(-hex, hey, hez), fromValues(hex, -hey, -hez), fromValues(-hex, -hey, -hez), fromValues(-hex, hey, -hez), fromValues(hex, hey, -hez)]; | ||
var faceAxes = [[0, 3, 1], [4, 7, 5], [1, 4, 0], [3, 6, 2], [1, 2, 4], [5, 6, 0] // LEFT | ||
var faceAxes = [// [3, 2, 0], // FRONT | ||
// [7, 6, 4], // BACK | ||
// [0, 1, 5], // TOP | ||
// [2, 3, 7], // BOTTOM | ||
// [2, 7, 1], // RIGHT | ||
// [6, 3, 5], // LEFT | ||
[0, 1, 3], [4, 5, 7], [3, 2, 6], [1, 0, 4], [1, 4, 2], [5, 0, 6] // LEFT | ||
]; | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], [0, -1, 0], [0, 1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], // [0, -1, 0], // TOP | ||
// [0, 1, 0], // BOTTOM | ||
[0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
]; | ||
@@ -453,2 +875,3 @@ var sides = { | ||
var uvs = []; | ||
var uvs1 = []; | ||
var indices = []; | ||
@@ -465,6 +888,6 @@ var vcounter = 0; | ||
for (j = 0; j <= vSegments; j++) { | ||
var temp1 = create(); | ||
var temp2 = create(); | ||
var temp3 = create(); | ||
var r = create(); | ||
var temp1 = create$1(); | ||
var temp2 = create$1(); | ||
var temp3 = create$1(); | ||
var r = create$1(); | ||
lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
@@ -478,3 +901,3 @@ lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
uvs.push(u, v); // pack as 3x2 | ||
uvs.push(u, 1.0 - v); // pack as 3x2 | ||
// 1/3 will be empty, but it's either that or stretched pixels | ||
@@ -489,2 +912,3 @@ // TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
v += Math.floor(side / 3) / 3; | ||
uvs1.push(u, 1.0 - v); | ||
@@ -507,6 +931,8 @@ if (i < uSegments && j < vSegments) { | ||
generateFace(sides.LEFT, ds, hs); | ||
indicesStart += 24; | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
uvs1All.push.apply(uvs1All, uvs1); | ||
indicesAll.push.apply(indicesAll, indices); | ||
@@ -518,3 +944,5 @@ }); | ||
normals: normalsAll, | ||
uvs: uvsAll | ||
uvs: uvsAll, | ||
uvs1: uvs1All, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; // TODO: barycentric & tangent | ||
@@ -525,8 +953,206 @@ } | ||
return CubeGeometry; | ||
}(Geometry); | ||
}(ProceduralGeometry); | ||
var vert = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n}"; // eslint-disable-line | ||
var SphereGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(SphereGeometry, _ProceduralGeometry); | ||
var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n}"; // eslint-disable-line | ||
var _super = _createSuper(SphereGeometry); | ||
function SphereGeometry() { | ||
_classCallCheck(this, SphereGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(SphereGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var indicesAll = []; | ||
var lon; | ||
var lat; | ||
var theta; | ||
var sinTheta; | ||
var cosTheta; | ||
var phi; | ||
var sinPhi; | ||
var cosPhi; | ||
var first; | ||
var second; | ||
var x; | ||
var y; | ||
var z; | ||
var u; | ||
var v; | ||
var indicesStart = 0; | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$radius = props.radius, | ||
radius = _props$radius === void 0 ? 0.5 : _props$radius, | ||
_props$latitudeBands = props.latitudeBands, | ||
latitudeBands = _props$latitudeBands === void 0 ? 16 : _props$latitudeBands, | ||
_props$longitudeBands = props.longitudeBands, | ||
longitudeBands = _props$longitudeBands === void 0 ? 16 : _props$longitudeBands; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var indices = []; | ||
for (lat = 0; lat <= latitudeBands; lat++) { | ||
theta = lat * Math.PI / latitudeBands; | ||
sinTheta = Math.sin(theta); | ||
cosTheta = Math.cos(theta); | ||
for (lon = 0; lon <= longitudeBands; lon++) { | ||
// Sweep the sphere from the positive Z axis to match a 3DS Max sphere | ||
phi = lon * 2 * Math.PI / longitudeBands - Math.PI / 2.0; | ||
sinPhi = Math.sin(phi); | ||
cosPhi = Math.cos(phi); | ||
x = cosPhi * sinTheta; | ||
y = cosTheta; | ||
z = sinPhi * sinTheta; | ||
u = 1.0 - lon / longitudeBands; | ||
v = 1.0 - lat / latitudeBands; | ||
positions.push(x * radius, y * radius, z * radius); | ||
normals.push(x, y, z); | ||
uvs.push(u, 1.0 - v); | ||
} | ||
} | ||
for (lat = 0; lat < latitudeBands; ++lat) { | ||
for (lon = 0; lon < longitudeBands; ++lon) { | ||
first = lat * (longitudeBands + 1) + lon; | ||
second = first + longitudeBands + 1; | ||
indices.push(first + 1 + indicesStart, second + indicesStart, first + indicesStart); | ||
indices.push(first + 1 + indicesStart, second + 1 + indicesStart, second + indicesStart); | ||
} | ||
} | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
indicesAll.push.apply(indicesAll, indices); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll, | ||
uvs1: uvsAll, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; | ||
} | ||
}]); | ||
return SphereGeometry; | ||
}(ProceduralGeometry); | ||
var TorusGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(TorusGeometry, _ProceduralGeometry); | ||
var _super = _createSuper(TorusGeometry); | ||
function TorusGeometry() { | ||
_classCallCheck(this, TorusGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(TorusGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var indicesAll = []; | ||
var x; | ||
var y; | ||
var z; | ||
var nx; | ||
var ny; | ||
var nz; | ||
var u; | ||
var v; | ||
var i; | ||
var j; | ||
var indicesStart = 0; | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$tubeRadius = props.tubeRadius, | ||
tubeRadius = _props$tubeRadius === void 0 ? 0.2 : _props$tubeRadius, | ||
_props$ringRadius = props.ringRadius, | ||
ringRadius = _props$ringRadius === void 0 ? 0.3 : _props$ringRadius, | ||
_props$segments = props.segments, | ||
segments = _props$segments === void 0 ? 30 : _props$segments, | ||
_props$sides = props.sides, | ||
sides = _props$sides === void 0 ? 20 : _props$sides; | ||
var rc = tubeRadius; | ||
var rt = ringRadius; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var indices = []; | ||
for (i = 0; i <= sides; i++) { | ||
for (j = 0; j <= segments; j++) { | ||
x = Math.cos(2.0 * Math.PI * j / segments) * (rt + rc * Math.cos(2.0 * Math.PI * i / sides)); | ||
y = Math.sin(2.0 * Math.PI * i / sides) * rc; | ||
z = Math.sin(2.0 * Math.PI * j / segments) * (rt + rc * Math.cos(2.0 * Math.PI * i / sides)); | ||
nx = Math.cos(2.0 * Math.PI * j / segments) * Math.cos(2.0 * Math.PI * i / sides); | ||
ny = Math.sin(2.0 * Math.PI * i / sides); | ||
nz = Math.sin(2.0 * Math.PI * j / segments) * Math.cos(2.0 * Math.PI * i / sides); | ||
u = i / sides; | ||
v = 1.0 - j / segments; | ||
positions.push(x, y, z); | ||
normals.push(nx, ny, nz); | ||
uvs.push(u, 1.0 - v); | ||
if (i < sides && j < segments) { | ||
var first = void 0, | ||
second = void 0, | ||
third = void 0, | ||
fourth = void 0; | ||
first = i * (segments + 1) + j; | ||
second = (i + 1) * (segments + 1) + j; | ||
third = i * (segments + 1) + (j + 1); | ||
fourth = (i + 1) * (segments + 1) + (j + 1); | ||
indices.push(first + indicesStart, second + indicesStart, third + indicesStart); | ||
indices.push(second + indicesStart, fourth + indicesStart, third + indicesStart); | ||
} | ||
} | ||
} | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
indicesAll.push.apply(indicesAll, indices); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll, | ||
uvs1: uvsAll, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; | ||
} | ||
}]); | ||
return TorusGeometry; | ||
}(ProceduralGeometry); | ||
var vert = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}"; // eslint-disable-line | ||
var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}"; // eslint-disable-line | ||
/** | ||
@@ -547,17 +1173,184 @@ * not affected by lights | ||
_this = _super.call(this); | ||
_this.map = void 0; | ||
_this = _super.call(this, _objectSpread2({ | ||
vertexShader: vert, | ||
fragmentShader: frag, | ||
cullMode: 2 | ||
/* Back */ | ||
}, props)); | ||
_this.defines = { | ||
USE_UV: true, | ||
USE_MAP: true | ||
USE_MAP: false, | ||
USE_WIREFRAME: false, | ||
USE_FOG: false | ||
}; | ||
_this.map = props === null || props === void 0 ? void 0 : props.map; | ||
_this.vertexShader = vert; | ||
_this.fragmentShader = frag; | ||
var _ref = props || {}, | ||
map = _ref.map, | ||
wireframe = _ref.wireframe; | ||
_this.setMap(map); | ||
_this.setWireframe(wireframe); | ||
_this.setFog(); | ||
return _this; | ||
} | ||
_createClass(MeshBasicMaterial, [{ | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
// vec3 u_Emissive; | ||
// float u_Shininess; | ||
// vec3 u_Specular; | ||
// vec3 u_AmbientLightColor; | ||
return 4 + 4 + 4; | ||
} | ||
}, { | ||
key: "setAttribute", | ||
value: function setAttribute(name, value) { | ||
_get(_getPrototypeOf(MeshBasicMaterial.prototype), "setAttribute", this).call(this, name, value); | ||
if (name === 'map') { | ||
this.setMap(value); | ||
} else if (name === 'fogType' || name === 'fogColor' || name === 'fogStart' || name === 'fogEnd' || name === 'fogDensity') { | ||
this.setFog(); | ||
} | ||
} | ||
}, { | ||
key: "setMap", | ||
value: function setMap(map) { | ||
// set MAP define | ||
this.defines.USE_MAP = !!map; | ||
this.addTexture(map, 'map'); | ||
} | ||
}, { | ||
key: "setWireframe", | ||
value: function setWireframe(wireframe) { | ||
this.defines.USE_WIREFRAME = !!wireframe; | ||
} | ||
}, { | ||
key: "setFog", | ||
value: function setFog() { | ||
this.defines.USE_FOG = !!this.props.fogType; | ||
} | ||
}]); | ||
return MeshBasicMaterial; | ||
}(Material); | ||
var vert$1 = "#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n vec4 position = vec4(a_Position, 1.0);\n\n gl_Position = project(position, u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n vec4 mvPosition = u_ViewMatrix * u_ModelMatrix * position;\n v_ViewPosition = - mvPosition.xyz;\n\n // v_ViewPosition = vec3(mvPosition) / mvPosition.w;\n\n mat3 normalWorld = mat3(transpose(inverse(u_ViewMatrix * u_ModelMatrix)));\n v_Normal = normalize(normalWorld * a_Normal);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}"; // eslint-disable-line | ||
var frag$1 = "#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n#ifdef USE_BUMPMAP\n uniform sampler2D u_BumpMap;\n\n // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen\n // http://api.unrealengine.com/attachments/Engine/Rendering/LightingAndShadows/BumpMappingWithoutTangentSpace/mm_sfgrad_bump.pdf\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( v_Uv );\n vec2 dSTdy = dFdy( v_Uv );\n\n float Hll = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv ).x;\n float dBx = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdx ).x - Hll;\n float dBy = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\n // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\n\n vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n vec3 vN = surf_norm;\t\t// normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n#ifdef USE_SPECULARMAP\n uniform sampler2D u_SpecularMap;\n#endif\nvec3 BRDF_Lambert(const in vec3 diffuseColor) {\n return RECIPROCAL_PI * diffuseColor;\n}\n\nvec3 F_Schlick(\n const in vec3 f0,\n const in float f90,\n const in float dotVH\n) {\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotVH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\n\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n}\n\nfloat D_BlinnPhong(\n const in float shininess,\n const in float dotNH\n) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\n\nvec3 BRDF_BlinnPhong(\n const in vec3 lightDir,\n const in vec3 viewDir,\n const in vec3 normal,\n const in vec3 specularColor,\n const in float shininess\n) {\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * ( G * D );\n}\n\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\n\nvoid RE_Direct_BlinnPhong(\n const in IncidentLight directLight,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n float dotNL = saturate(dot(geometry.normal, directLight.direction));\n vec3 irradiance = dotNL * directLight.color;\n\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\n\nvoid RE_IndirectDiffuse_BlinnPhong(\n const in vec3 irradiance,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\n\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n float specularStrength = 1.0;\n\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture(SAMPLER_2D(u_SpecularMap), v_Uv);\n specularStrength = texelSpecular.r;\n#endif\n\n float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n vec3 normal = normalize(v_Normal);\n #ifdef USE_DOUBLESIDE\n\t\tnormal = normal * faceDirection;\n\t#endif\n\n // #ifdef USE_TANGENT\n // vec3 tangent = normalize( vTangent );\n // vec3 bitangent = normalize( vBitangent );\n\n // #ifdef DOUBLE_SIDED\n // tangent = tangent * faceDirection;\n // bitangent = bitangent * faceDirection;\n // #endif\n // #endif\n\n #ifdef USE_BUMPMAP\n\tnormal = perturbNormalArb( - v_ViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_LIGHT\n vec4 diffuseColor = gl_FragColor;\n ReflectedLight reflectedLight = ReflectedLight(vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ));\n vec3 totalEmissiveRadiance = u_Emissive;\n\n BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = u_Specular;\nmaterial.specularShininess = u_Shininess;\nmaterial.specularStrength = specularStrength;\n\n GeometricContext geometry;\n geometry.position = - v_ViewPosition;\n geometry.normal = normal;\n geometry.viewDir = u_IsOrtho ? vec3(0, 0, 1) : normalize(v_ViewPosition);\n\n IncidentLight directLight;\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n directionalLight = directionalLights[ i ];\n\n getDirectionalLightInfo( directionalLight, geometry, directLight );\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance(u_AmbientLightColor);\n\n // irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n // #if ( NUM_HEMI_LIGHTS > 0 )\n // #pragma unroll_loop_start\n // for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n // irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n // }\n // #pragma unroll_loop_end\n // #endif\n #endif\n\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n #endif\n\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n #endif\n\n vec3 outgoingLight = reflectedLight.directDiffuse +\n reflectedLight.indirectDiffuse + \n reflectedLight.directSpecular + \n reflectedLight.indirectSpecular + \n totalEmissiveRadiance;\n\n gl_FragColor = vec4(outgoingLight, diffuseColor.a);\n #endif\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}"; // eslint-disable-line | ||
var MeshPhongMaterial = /*#__PURE__*/function (_MeshBasicMaterial) { | ||
_inherits(MeshPhongMaterial, _MeshBasicMaterial); | ||
var _super = _createSuper(MeshPhongMaterial); | ||
function MeshPhongMaterial(props) { | ||
var _this; | ||
_classCallCheck(this, MeshPhongMaterial); | ||
_this = _super.call(this, _objectSpread2({ | ||
vertexShader: vert$1, | ||
fragmentShader: frag$1, | ||
emissive: 'black', | ||
specular: '#111111', | ||
shininess: 30, | ||
bumpScale: 1, | ||
doubleSide: false | ||
}, props)); | ||
var _ref = props || {}, | ||
specularMap = _ref.specularMap, | ||
bumpMap = _ref.bumpMap, | ||
doubleSide = _ref.doubleSide; | ||
_this.setSpecularMap(specularMap); | ||
_this.setBumpMap(bumpMap); | ||
_this.setDoubleSide(doubleSide); | ||
return _this; | ||
} | ||
_createClass(MeshPhongMaterial, [{ | ||
key: "setAttribute", | ||
value: function setAttribute(name, value) { | ||
// @ts-ignore | ||
_get(_getPrototypeOf(MeshPhongMaterial.prototype), "setAttribute", this).call(this, name, value); | ||
if (name === 'specularMap') { | ||
this.setSpecularMap(value); | ||
} else if (name === 'bumpMap') { | ||
this.setBumpMap(value); | ||
} else if (name === 'doubleSide') { | ||
this.setDoubleSide(value); | ||
} | ||
} | ||
}, { | ||
key: "setSpecularMap", | ||
value: function setSpecularMap(map) { | ||
this.defines.USE_SPECULARMAP = !!map; | ||
this.addTexture(map, 'specular-map'); | ||
} | ||
}, { | ||
key: "setBumpMap", | ||
value: function setBumpMap(map) { | ||
this.defines.USE_BUMPMAP = !!map; | ||
this.addTexture(map, 'bump-map'); | ||
} | ||
}, { | ||
key: "setDoubleSide", | ||
value: function setDoubleSide(enabled) { | ||
this.defines.USE_DOUBLESIDE = enabled; | ||
} | ||
}, { | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
// vec3 u_Emissive; | ||
// float u_Shininess; | ||
// vec3 u_Specular; | ||
// vec3 u_AmbientLightColor; | ||
return 4 + 4 + 4; | ||
} | ||
}]); | ||
return MeshPhongMaterial; | ||
}(MeshBasicMaterial); | ||
var _excluded = ["style"]; | ||
var DirectionalLight = /*#__PURE__*/function (_Light) { | ||
_inherits(DirectionalLight, _Light); | ||
var _super = _createSuper(DirectionalLight); | ||
function DirectionalLight() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
style = _ref.style, | ||
rest = _objectWithoutProperties(_ref, _excluded); | ||
_classCallCheck(this, DirectionalLight); | ||
return _super.call(this, _objectSpread2({ | ||
style: _objectSpread2({ | ||
direction: fromValues(0, -1, 0) | ||
}, style) | ||
}, rest)); | ||
} | ||
_createClass(DirectionalLight, [{ | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
return 4 + 4; | ||
} | ||
}]); | ||
return DirectionalLight; | ||
}(Light); | ||
// globalContainer.register(CubeUpdater); | ||
@@ -591,2 +1384,2 @@ // globalContainer.register(SphereUpdater); | ||
export { CubeGeometry, MeshBasicMaterial, Plugin, containerModule }; | ||
export { CubeGeometry, DirectionalLight, MeshBasicMaterial, MeshPhongMaterial, Plugin, ProceduralGeometry, ProceduralGeometryAttributeLocation, SphereGeometry, TorusGeometry, containerModule }; |
@@ -127,2 +127,38 @@ 'use strict'; | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -165,2 +201,32 @@ if (self === void 0) { | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get; | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
/** | ||
@@ -183,2 +249,209 @@ * Common utilities | ||
/** | ||
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied. | ||
* @module mat4 | ||
*/ | ||
/** | ||
* Creates a new identity mat4 | ||
* | ||
* @returns {mat4} a new 4x4 matrix | ||
*/ | ||
function create() { | ||
var out = new ARRAY_TYPE(16); | ||
if (ARRAY_TYPE != Float32Array) { | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 0; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 0; | ||
out[9] = 0; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
} | ||
out[0] = 1; | ||
out[5] = 1; | ||
out[10] = 1; | ||
out[15] = 1; | ||
return out; | ||
} | ||
/** | ||
* Copy the values from one mat4 to another | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function copy(out, a) { | ||
out[0] = a[0]; | ||
out[1] = a[1]; | ||
out[2] = a[2]; | ||
out[3] = a[3]; | ||
out[4] = a[4]; | ||
out[5] = a[5]; | ||
out[6] = a[6]; | ||
out[7] = a[7]; | ||
out[8] = a[8]; | ||
out[9] = a[9]; | ||
out[10] = a[10]; | ||
out[11] = a[11]; | ||
out[12] = a[12]; | ||
out[13] = a[13]; | ||
out[14] = a[14]; | ||
out[15] = a[15]; | ||
return out; | ||
} | ||
/** | ||
* Transpose the values of a mat4 | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function transpose(out, a) { | ||
// If we are transposing ourselves we can skip a few steps but have to cache some values | ||
if (out === a) { | ||
var a01 = a[1], | ||
a02 = a[2], | ||
a03 = a[3]; | ||
var a12 = a[6], | ||
a13 = a[7]; | ||
var a23 = a[11]; | ||
out[1] = a[4]; | ||
out[2] = a[8]; | ||
out[3] = a[12]; | ||
out[4] = a01; | ||
out[6] = a[9]; | ||
out[7] = a[13]; | ||
out[8] = a02; | ||
out[9] = a12; | ||
out[11] = a[14]; | ||
out[12] = a03; | ||
out[13] = a13; | ||
out[14] = a23; | ||
} else { | ||
out[0] = a[0]; | ||
out[1] = a[4]; | ||
out[2] = a[8]; | ||
out[3] = a[12]; | ||
out[4] = a[1]; | ||
out[5] = a[5]; | ||
out[6] = a[9]; | ||
out[7] = a[13]; | ||
out[8] = a[2]; | ||
out[9] = a[6]; | ||
out[10] = a[10]; | ||
out[11] = a[14]; | ||
out[12] = a[3]; | ||
out[13] = a[7]; | ||
out[14] = a[11]; | ||
out[15] = a[15]; | ||
} | ||
return out; | ||
} | ||
/** | ||
* Inverts a mat4 | ||
* | ||
* @param {mat4} out the receiving matrix | ||
* @param {ReadonlyMat4} a the source matrix | ||
* @returns {mat4} out | ||
*/ | ||
function invert(out, a) { | ||
var a00 = a[0], | ||
a01 = a[1], | ||
a02 = a[2], | ||
a03 = a[3]; | ||
var a10 = a[4], | ||
a11 = a[5], | ||
a12 = a[6], | ||
a13 = a[7]; | ||
var a20 = a[8], | ||
a21 = a[9], | ||
a22 = a[10], | ||
a23 = a[11]; | ||
var a30 = a[12], | ||
a31 = a[13], | ||
a32 = a[14], | ||
a33 = a[15]; | ||
var b00 = a00 * a11 - a01 * a10; | ||
var b01 = a00 * a12 - a02 * a10; | ||
var b02 = a00 * a13 - a03 * a10; | ||
var b03 = a01 * a12 - a02 * a11; | ||
var b04 = a01 * a13 - a03 * a11; | ||
var b05 = a02 * a13 - a03 * a12; | ||
var b06 = a20 * a31 - a21 * a30; | ||
var b07 = a20 * a32 - a22 * a30; | ||
var b08 = a20 * a33 - a23 * a30; | ||
var b09 = a21 * a32 - a22 * a31; | ||
var b10 = a21 * a33 - a23 * a31; | ||
var b11 = a22 * a33 - a23 * a32; // Calculate the determinant | ||
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; | ||
if (!det) { | ||
return null; | ||
} | ||
det = 1.0 / det; | ||
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; | ||
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; | ||
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; | ||
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; | ||
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; | ||
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; | ||
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; | ||
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; | ||
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; | ||
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; | ||
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; | ||
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; | ||
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; | ||
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; | ||
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; | ||
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; | ||
return out; | ||
} | ||
/** | ||
* Creates a matrix from a vector scaling | ||
* This is equivalent to (but much faster than): | ||
* | ||
* mat4.identity(dest); | ||
* mat4.scale(dest, dest, vec); | ||
* | ||
* @param {mat4} out mat4 receiving operation result | ||
* @param {ReadonlyVec3} v Scaling vector | ||
* @returns {mat4} out | ||
*/ | ||
function fromScaling(out, v) { | ||
out[0] = v[0]; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
out[4] = 0; | ||
out[5] = v[1]; | ||
out[6] = 0; | ||
out[7] = 0; | ||
out[8] = 0; | ||
out[9] = 0; | ||
out[10] = v[2]; | ||
out[11] = 0; | ||
out[12] = 0; | ||
out[13] = 0; | ||
out[14] = 0; | ||
out[15] = 1; | ||
return out; | ||
} | ||
/** | ||
* 3 Dimensional Vector | ||
@@ -194,3 +467,3 @@ * @module vec3 | ||
function create() { | ||
function create$1() { | ||
var out = new ARRAY_TYPE(3); | ||
@@ -291,3 +564,3 @@ | ||
var forEach = function () { | ||
var vec = create(); | ||
var vec = create$1(); | ||
return function (a, stride, offset, count, fn, arg) { | ||
@@ -324,38 +597,163 @@ var i, l; | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeGeometry = /*#__PURE__*/function (_Geometry) { | ||
_inherits(CubeGeometry, _Geometry); | ||
/** | ||
* 4 Dimensional Vector | ||
* @module vec4 | ||
*/ | ||
var _super = _createSuper(CubeGeometry); | ||
/** | ||
* Creates a new, empty vec4 | ||
* | ||
* @returns {vec4} a new 4D vector | ||
*/ | ||
function CubeGeometry(props) { | ||
var _this; | ||
function create$2() { | ||
var out = new ARRAY_TYPE(4); | ||
_classCallCheck(this, CubeGeometry); | ||
if (ARRAY_TYPE != Float32Array) { | ||
out[0] = 0; | ||
out[1] = 0; | ||
out[2] = 0; | ||
out[3] = 0; | ||
} | ||
_this = _super.call(this); | ||
_this.props = void 0; | ||
_this.props = _objectSpread2(_objectSpread2({}, props), {}, { | ||
// defaults | ||
widthSegments: 1, | ||
heightSegments: 1, | ||
depthSegments: 1 | ||
}); | ||
return _this; | ||
return out; | ||
} | ||
/** | ||
* Transforms the vec4 with a mat4. | ||
* | ||
* @param {vec4} out the receiving vector | ||
* @param {ReadonlyVec4} a the vector to transform | ||
* @param {ReadonlyMat4} m matrix to transform with | ||
* @returns {vec4} out | ||
*/ | ||
function transformMat4(out, a, m) { | ||
var x = a[0], | ||
y = a[1], | ||
z = a[2], | ||
w = a[3]; | ||
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w; | ||
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w; | ||
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w; | ||
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w; | ||
return out; | ||
} | ||
/** | ||
* Perform some operation over an array of vec4s. | ||
* | ||
* @param {Array} a the array of vectors to iterate over | ||
* @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed | ||
* @param {Number} offset Number of elements to skip at the beginning of the array | ||
* @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array | ||
* @param {Function} fn Function to call for each vector in the array | ||
* @param {Object} [arg] additional argument to pass to fn | ||
* @returns {Array} a | ||
* @function | ||
*/ | ||
var forEach$1 = function () { | ||
var vec = create$2(); | ||
return function (a, stride, offset, count, fn, arg) { | ||
var i, l; | ||
if (!stride) { | ||
stride = 4; | ||
} | ||
if (!offset) { | ||
offset = 0; | ||
} | ||
if (count) { | ||
l = Math.min(count * stride + offset, a.length); | ||
} else { | ||
l = a.length; | ||
} | ||
for (i = offset; i < l; i += stride) { | ||
vec[0] = a[i]; | ||
vec[1] = a[i + 1]; | ||
vec[2] = a[i + 2]; | ||
vec[3] = a[i + 3]; | ||
fn(vec, vec, arg); | ||
a[i] = vec[0]; | ||
a[i + 1] = vec[1]; | ||
a[i + 2] = vec[2]; | ||
a[i + 3] = vec[3]; | ||
} | ||
return a; | ||
}; | ||
}(); | ||
(function (ProceduralGeometryAttributeLocation) { | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["POSITION"] = 1] = "POSITION"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["NORMAL"] = 2] = "NORMAL"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["UV"] = 3] = "UV"; | ||
ProceduralGeometryAttributeLocation[ProceduralGeometryAttributeLocation["MAX"] = 4] = "MAX"; | ||
})(exports.ProceduralGeometryAttributeLocation || (exports.ProceduralGeometryAttributeLocation = {})); | ||
var ProceduralGeometry = /*#__PURE__*/function (_BufferGeometry) { | ||
_inherits(ProceduralGeometry, _BufferGeometry); | ||
var _super = _createSuper(ProceduralGeometry); | ||
function ProceduralGeometry() { | ||
_classCallCheck(this, ProceduralGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(CubeGeometry, [{ | ||
key: "init", | ||
value: function init() { | ||
var _this$buildAttributes = this.buildAttributes([this.props]), | ||
indices = _this$buildAttributes.indices, | ||
positions = _this$buildAttributes.positions, | ||
normals = _this$buildAttributes.normals, | ||
uvs = _this$buildAttributes.uvs; | ||
_createClass(ProceduralGeometry, [{ | ||
key: "applyMat4", | ||
value: function applyMat4(mat) { | ||
var positions = this.vertexBuffers[exports.ProceduralGeometryAttributeLocation.POSITION]; | ||
var v = create$2(); | ||
for (var i = 0; i < positions.byteLength / 4; i += 3) { | ||
v[0] = positions[i]; | ||
v[1] = positions[i + 1]; | ||
v[2] = positions[i + 2]; | ||
v[3] = 1; | ||
transformMat4(v, v, mat); | ||
positions[i] = v[0]; | ||
positions[i + 1] = v[1]; | ||
positions[i + 2] = v[2]; | ||
} | ||
var normals = this.vertexBuffers[exports.ProceduralGeometryAttributeLocation.NORMAL]; | ||
var normalMatrix = copy(create(), mat); | ||
invert(normalMatrix, normalMatrix); | ||
transpose(normalMatrix, normalMatrix); | ||
for (var _i = 0; _i < normals.byteLength / 4; _i += 3) { | ||
v[0] = normals[_i]; | ||
v[1] = normals[_i + 1]; | ||
v[2] = normals[_i + 2]; | ||
v[3] = 1; | ||
transformMat4(v, v, normalMatrix); | ||
normals[_i] = v[0]; | ||
normals[_i + 1] = v[1]; | ||
normals[_i + 2] = v[2]; | ||
} // transform tangent | ||
} | ||
}, { | ||
key: "getBoundingBox", | ||
value: function getBoundingBox() {// 根据 ProceduralGeometryAttributeLocation.POSITION 计算 | ||
} | ||
}, { | ||
key: "build", | ||
value: function build(meshes) { | ||
var _this$createTopology = this.createTopology(meshes), | ||
indices = _this$createTopology.indices, | ||
positions = _this$createTopology.positions, | ||
normals = _this$createTopology.normals, | ||
uvs = _this$createTopology.uvs, | ||
vertexCountPerInstance = _this$createTopology.vertexCountPerInstance; | ||
this.setIndices(new Uint32Array(indices)); | ||
this.vertexCount = 36; | ||
this.vertexCount = vertexCountPerInstance; | ||
this.setVertexBuffer({ | ||
bufferIndex: 1, | ||
bufferIndex: exports.ProceduralGeometryAttributeLocation.POSITION, | ||
byteStride: 4 * 3, | ||
@@ -373,3 +771,3 @@ frequency: 1 | ||
this.setVertexBuffer({ | ||
bufferIndex: 2, | ||
bufferIndex: exports.ProceduralGeometryAttributeLocation.NORMAL, | ||
byteStride: 4 * 3, | ||
@@ -387,3 +785,3 @@ frequency: 1 | ||
this.setVertexBuffer({ | ||
bufferIndex: 3, | ||
bufferIndex: exports.ProceduralGeometryAttributeLocation.UV, | ||
byteStride: 4 * 2, | ||
@@ -399,23 +797,37 @@ frequency: 1 | ||
data: Float32Array.from(uvs) | ||
}); | ||
}); // flip Y | ||
this.applyMat4(fromScaling(create(), fromValues(1, -1, 1))); | ||
} | ||
}, { | ||
key: "updateAttribute", | ||
value: function updateAttribute(name, value, index) { | ||
if (name === 'width' || name === 'height' || name === 'depth') { | ||
var _this$buildAttributes2 = this.buildAttributes([this.props]), | ||
positions = _this$buildAttributes2.positions; | ||
}]); | ||
this.updateVertexBuffer(1, 10, index, new Uint8Array(new Float32Array(positions).buffer)); | ||
} | ||
} | ||
}, { | ||
key: "buildAttributes", | ||
value: function buildAttributes(propsList) { | ||
return ProceduralGeometry; | ||
}(gPluginWebglRenderer.BufferGeometry); | ||
var primitiveUv1Padding = 4.0 / 64; | ||
var primitiveUv1PaddingScale = 1.0 - primitiveUv1Padding * 2; | ||
var CubeGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(CubeGeometry, _ProceduralGeometry); | ||
var _super = _createSuper(CubeGeometry); | ||
function CubeGeometry() { | ||
_classCallCheck(this, CubeGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(CubeGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var uvs1All = []; | ||
var indicesAll = []; | ||
var indicesStart = 0; | ||
propsList.forEach(function (props) { | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$widthSegments = props.widthSegments, | ||
@@ -440,5 +852,13 @@ widthSegments = _props$widthSegments === void 0 ? 1 : _props$widthSegments, | ||
var corners = [fromValues(-hex, -hey, hez), fromValues(hex, -hey, hez), fromValues(hex, hey, hez), fromValues(-hex, hey, hez), fromValues(hex, -hey, -hez), fromValues(-hex, -hey, -hez), fromValues(-hex, hey, -hez), fromValues(hex, hey, -hez)]; | ||
var faceAxes = [[0, 3, 1], [4, 7, 5], [1, 4, 0], [3, 6, 2], [1, 2, 4], [5, 6, 0] // LEFT | ||
var faceAxes = [// [3, 2, 0], // FRONT | ||
// [7, 6, 4], // BACK | ||
// [0, 1, 5], // TOP | ||
// [2, 3, 7], // BOTTOM | ||
// [2, 7, 1], // RIGHT | ||
// [6, 3, 5], // LEFT | ||
[0, 1, 3], [4, 5, 7], [3, 2, 6], [1, 0, 4], [1, 4, 2], [5, 0, 6] // LEFT | ||
]; | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], [0, -1, 0], [0, 1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
var faceNormals = [[0, 0, 1], [0, 0, -1], // [0, -1, 0], // TOP | ||
// [0, 1, 0], // BOTTOM | ||
[0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0] // LEFT | ||
]; | ||
@@ -456,2 +876,3 @@ var sides = { | ||
var uvs = []; | ||
var uvs1 = []; | ||
var indices = []; | ||
@@ -468,6 +889,6 @@ var vcounter = 0; | ||
for (j = 0; j <= vSegments; j++) { | ||
var temp1 = create(); | ||
var temp2 = create(); | ||
var temp3 = create(); | ||
var r = create(); | ||
var temp1 = create$1(); | ||
var temp2 = create$1(); | ||
var temp3 = create$1(); | ||
var r = create$1(); | ||
lerp(temp1, corners[faceAxes[side][0]], corners[faceAxes[side][1]], i / uSegments); | ||
@@ -481,3 +902,3 @@ lerp(temp2, corners[faceAxes[side][0]], corners[faceAxes[side][2]], j / vSegments); | ||
normals.push(faceNormals[side][0], faceNormals[side][1], faceNormals[side][2]); | ||
uvs.push(u, v); // pack as 3x2 | ||
uvs.push(u, 1.0 - v); // pack as 3x2 | ||
// 1/3 will be empty, but it's either that or stretched pixels | ||
@@ -492,2 +913,3 @@ // TODO: generate non-rectangular lightMaps, so we could use space without stretching | ||
v += Math.floor(side / 3) / 3; | ||
uvs1.push(u, 1.0 - v); | ||
@@ -510,6 +932,8 @@ if (i < uSegments && j < vSegments) { | ||
generateFace(sides.LEFT, ds, hs); | ||
indicesStart += 24; | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
uvs1All.push.apply(uvs1All, uvs1); | ||
indicesAll.push.apply(indicesAll, indices); | ||
@@ -521,3 +945,5 @@ }); | ||
normals: normalsAll, | ||
uvs: uvsAll | ||
uvs: uvsAll, | ||
uvs1: uvs1All, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; // TODO: barycentric & tangent | ||
@@ -528,8 +954,206 @@ } | ||
return CubeGeometry; | ||
}(gPluginWebglRenderer.Geometry); | ||
}(ProceduralGeometry); | ||
var vert = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n}"; // eslint-disable-line | ||
var SphereGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(SphereGeometry, _ProceduralGeometry); | ||
var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n}"; // eslint-disable-line | ||
var _super = _createSuper(SphereGeometry); | ||
function SphereGeometry() { | ||
_classCallCheck(this, SphereGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(SphereGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var indicesAll = []; | ||
var lon; | ||
var lat; | ||
var theta; | ||
var sinTheta; | ||
var cosTheta; | ||
var phi; | ||
var sinPhi; | ||
var cosPhi; | ||
var first; | ||
var second; | ||
var x; | ||
var y; | ||
var z; | ||
var u; | ||
var v; | ||
var indicesStart = 0; | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$radius = props.radius, | ||
radius = _props$radius === void 0 ? 0.5 : _props$radius, | ||
_props$latitudeBands = props.latitudeBands, | ||
latitudeBands = _props$latitudeBands === void 0 ? 16 : _props$latitudeBands, | ||
_props$longitudeBands = props.longitudeBands, | ||
longitudeBands = _props$longitudeBands === void 0 ? 16 : _props$longitudeBands; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var indices = []; | ||
for (lat = 0; lat <= latitudeBands; lat++) { | ||
theta = lat * Math.PI / latitudeBands; | ||
sinTheta = Math.sin(theta); | ||
cosTheta = Math.cos(theta); | ||
for (lon = 0; lon <= longitudeBands; lon++) { | ||
// Sweep the sphere from the positive Z axis to match a 3DS Max sphere | ||
phi = lon * 2 * Math.PI / longitudeBands - Math.PI / 2.0; | ||
sinPhi = Math.sin(phi); | ||
cosPhi = Math.cos(phi); | ||
x = cosPhi * sinTheta; | ||
y = cosTheta; | ||
z = sinPhi * sinTheta; | ||
u = 1.0 - lon / longitudeBands; | ||
v = 1.0 - lat / latitudeBands; | ||
positions.push(x * radius, y * radius, z * radius); | ||
normals.push(x, y, z); | ||
uvs.push(u, 1.0 - v); | ||
} | ||
} | ||
for (lat = 0; lat < latitudeBands; ++lat) { | ||
for (lon = 0; lon < longitudeBands; ++lon) { | ||
first = lat * (longitudeBands + 1) + lon; | ||
second = first + longitudeBands + 1; | ||
indices.push(first + 1 + indicesStart, second + indicesStart, first + indicesStart); | ||
indices.push(first + 1 + indicesStart, second + 1 + indicesStart, second + indicesStart); | ||
} | ||
} | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
indicesAll.push.apply(indicesAll, indices); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll, | ||
uvs1: uvsAll, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; | ||
} | ||
}]); | ||
return SphereGeometry; | ||
}(ProceduralGeometry); | ||
var TorusGeometry = /*#__PURE__*/function (_ProceduralGeometry) { | ||
_inherits(TorusGeometry, _ProceduralGeometry); | ||
var _super = _createSuper(TorusGeometry); | ||
function TorusGeometry() { | ||
_classCallCheck(this, TorusGeometry); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(TorusGeometry, [{ | ||
key: "createTopology", | ||
value: function createTopology(meshes) { | ||
var positionsAll = []; | ||
var normalsAll = []; | ||
var uvsAll = []; | ||
var indicesAll = []; | ||
var x; | ||
var y; | ||
var z; | ||
var nx; | ||
var ny; | ||
var nz; | ||
var u; | ||
var v; | ||
var i; | ||
var j; | ||
var indicesStart = 0; | ||
var vertexCountPerInstance = 0; | ||
meshes.map(function (mesh) { | ||
return mesh.style; | ||
}).forEach(function (props) { | ||
var _props$tubeRadius = props.tubeRadius, | ||
tubeRadius = _props$tubeRadius === void 0 ? 0.2 : _props$tubeRadius, | ||
_props$ringRadius = props.ringRadius, | ||
ringRadius = _props$ringRadius === void 0 ? 0.3 : _props$ringRadius, | ||
_props$segments = props.segments, | ||
segments = _props$segments === void 0 ? 30 : _props$segments, | ||
_props$sides = props.sides, | ||
sides = _props$sides === void 0 ? 20 : _props$sides; | ||
var rc = tubeRadius; | ||
var rt = ringRadius; | ||
var positions = []; | ||
var normals = []; | ||
var uvs = []; | ||
var indices = []; | ||
for (i = 0; i <= sides; i++) { | ||
for (j = 0; j <= segments; j++) { | ||
x = Math.cos(2.0 * Math.PI * j / segments) * (rt + rc * Math.cos(2.0 * Math.PI * i / sides)); | ||
y = Math.sin(2.0 * Math.PI * i / sides) * rc; | ||
z = Math.sin(2.0 * Math.PI * j / segments) * (rt + rc * Math.cos(2.0 * Math.PI * i / sides)); | ||
nx = Math.cos(2.0 * Math.PI * j / segments) * Math.cos(2.0 * Math.PI * i / sides); | ||
ny = Math.sin(2.0 * Math.PI * i / sides); | ||
nz = Math.sin(2.0 * Math.PI * j / segments) * Math.cos(2.0 * Math.PI * i / sides); | ||
u = i / sides; | ||
v = 1.0 - j / segments; | ||
positions.push(x, y, z); | ||
normals.push(nx, ny, nz); | ||
uvs.push(u, 1.0 - v); | ||
if (i < sides && j < segments) { | ||
var first = void 0, | ||
second = void 0, | ||
third = void 0, | ||
fourth = void 0; | ||
first = i * (segments + 1) + j; | ||
second = (i + 1) * (segments + 1) + j; | ||
third = i * (segments + 1) + (j + 1); | ||
fourth = (i + 1) * (segments + 1) + (j + 1); | ||
indices.push(first + indicesStart, second + indicesStart, third + indicesStart); | ||
indices.push(second + indicesStart, fourth + indicesStart, third + indicesStart); | ||
} | ||
} | ||
} | ||
vertexCountPerInstance = indices.length; | ||
indicesStart += vertexCountPerInstance; | ||
positionsAll.push.apply(positionsAll, positions); | ||
normalsAll.push.apply(normalsAll, normals); | ||
uvsAll.push.apply(uvsAll, uvs); | ||
indicesAll.push.apply(indicesAll, indices); | ||
}); | ||
return { | ||
indices: indicesAll, | ||
positions: positionsAll, | ||
normals: normalsAll, | ||
uvs: uvsAll, | ||
uvs1: uvsAll, | ||
vertexCountPerInstance: vertexCountPerInstance | ||
}; | ||
} | ||
}]); | ||
return TorusGeometry; | ||
}(ProceduralGeometry); | ||
var vert = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}"; // eslint-disable-line | ||
var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}"; // eslint-disable-line | ||
/** | ||
@@ -550,17 +1174,184 @@ * not affected by lights | ||
_this = _super.call(this); | ||
_this.map = void 0; | ||
_this = _super.call(this, _objectSpread2({ | ||
vertexShader: vert, | ||
fragmentShader: frag, | ||
cullMode: 2 | ||
/* Back */ | ||
}, props)); | ||
_this.defines = { | ||
USE_UV: true, | ||
USE_MAP: true | ||
USE_MAP: false, | ||
USE_WIREFRAME: false, | ||
USE_FOG: false | ||
}; | ||
_this.map = props === null || props === void 0 ? void 0 : props.map; | ||
_this.vertexShader = vert; | ||
_this.fragmentShader = frag; | ||
var _ref = props || {}, | ||
map = _ref.map, | ||
wireframe = _ref.wireframe; | ||
_this.setMap(map); | ||
_this.setWireframe(wireframe); | ||
_this.setFog(); | ||
return _this; | ||
} | ||
_createClass(MeshBasicMaterial, [{ | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
// vec3 u_Emissive; | ||
// float u_Shininess; | ||
// vec3 u_Specular; | ||
// vec3 u_AmbientLightColor; | ||
return 4 + 4 + 4; | ||
} | ||
}, { | ||
key: "setAttribute", | ||
value: function setAttribute(name, value) { | ||
_get(_getPrototypeOf(MeshBasicMaterial.prototype), "setAttribute", this).call(this, name, value); | ||
if (name === 'map') { | ||
this.setMap(value); | ||
} else if (name === 'fogType' || name === 'fogColor' || name === 'fogStart' || name === 'fogEnd' || name === 'fogDensity') { | ||
this.setFog(); | ||
} | ||
} | ||
}, { | ||
key: "setMap", | ||
value: function setMap(map) { | ||
// set MAP define | ||
this.defines.USE_MAP = !!map; | ||
this.addTexture(map, 'map'); | ||
} | ||
}, { | ||
key: "setWireframe", | ||
value: function setWireframe(wireframe) { | ||
this.defines.USE_WIREFRAME = !!wireframe; | ||
} | ||
}, { | ||
key: "setFog", | ||
value: function setFog() { | ||
this.defines.USE_FOG = !!this.props.fogType; | ||
} | ||
}]); | ||
return MeshBasicMaterial; | ||
}(gPluginWebglRenderer.Material); | ||
var vert$1 = "#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n vec4 position = vec4(a_Position, 1.0);\n\n gl_Position = project(position, u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n vec4 mvPosition = u_ViewMatrix * u_ModelMatrix * position;\n v_ViewPosition = - mvPosition.xyz;\n\n // v_ViewPosition = vec3(mvPosition) / mvPosition.w;\n\n mat3 normalWorld = mat3(transpose(inverse(u_ViewMatrix * u_ModelMatrix)));\n v_Normal = normalize(normalWorld * a_Normal);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}"; // eslint-disable-line | ||
var frag$1 = "#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n#ifdef USE_BUMPMAP\n uniform sampler2D u_BumpMap;\n\n // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen\n // http://api.unrealengine.com/attachments/Engine/Rendering/LightingAndShadows/BumpMappingWithoutTangentSpace/mm_sfgrad_bump.pdf\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( v_Uv );\n vec2 dSTdy = dFdy( v_Uv );\n\n float Hll = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv ).x;\n float dBx = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdx ).x - Hll;\n float dBy = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\n // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\n\n vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n vec3 vN = surf_norm;\t\t// normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n#ifdef USE_SPECULARMAP\n uniform sampler2D u_SpecularMap;\n#endif\nvec3 BRDF_Lambert(const in vec3 diffuseColor) {\n return RECIPROCAL_PI * diffuseColor;\n}\n\nvec3 F_Schlick(\n const in vec3 f0,\n const in float f90,\n const in float dotVH\n) {\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotVH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\n\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n}\n\nfloat D_BlinnPhong(\n const in float shininess,\n const in float dotNH\n) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\n\nvec3 BRDF_BlinnPhong(\n const in vec3 lightDir,\n const in vec3 viewDir,\n const in vec3 normal,\n const in vec3 specularColor,\n const in float shininess\n) {\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * ( G * D );\n}\n\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\n\nvoid RE_Direct_BlinnPhong(\n const in IncidentLight directLight,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n float dotNL = saturate(dot(geometry.normal, directLight.direction));\n vec3 irradiance = dotNL * directLight.color;\n\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\n\nvoid RE_IndirectDiffuse_BlinnPhong(\n const in vec3 irradiance,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\n\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n float specularStrength = 1.0;\n\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture(SAMPLER_2D(u_SpecularMap), v_Uv);\n specularStrength = texelSpecular.r;\n#endif\n\n float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n vec3 normal = normalize(v_Normal);\n #ifdef USE_DOUBLESIDE\n\t\tnormal = normal * faceDirection;\n\t#endif\n\n // #ifdef USE_TANGENT\n // vec3 tangent = normalize( vTangent );\n // vec3 bitangent = normalize( vBitangent );\n\n // #ifdef DOUBLE_SIDED\n // tangent = tangent * faceDirection;\n // bitangent = bitangent * faceDirection;\n // #endif\n // #endif\n\n #ifdef USE_BUMPMAP\n\tnormal = perturbNormalArb( - v_ViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_LIGHT\n vec4 diffuseColor = gl_FragColor;\n ReflectedLight reflectedLight = ReflectedLight(vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ));\n vec3 totalEmissiveRadiance = u_Emissive;\n\n BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = u_Specular;\nmaterial.specularShininess = u_Shininess;\nmaterial.specularStrength = specularStrength;\n\n GeometricContext geometry;\n geometry.position = - v_ViewPosition;\n geometry.normal = normal;\n geometry.viewDir = u_IsOrtho ? vec3(0, 0, 1) : normalize(v_ViewPosition);\n\n IncidentLight directLight;\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n directionalLight = directionalLights[ i ];\n\n getDirectionalLightInfo( directionalLight, geometry, directLight );\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance(u_AmbientLightColor);\n\n // irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n // #if ( NUM_HEMI_LIGHTS > 0 )\n // #pragma unroll_loop_start\n // for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n // irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n // }\n // #pragma unroll_loop_end\n // #endif\n #endif\n\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n #endif\n\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n #endif\n\n vec3 outgoingLight = reflectedLight.directDiffuse +\n reflectedLight.indirectDiffuse + \n reflectedLight.directSpecular + \n reflectedLight.indirectSpecular + \n totalEmissiveRadiance;\n\n gl_FragColor = vec4(outgoingLight, diffuseColor.a);\n #endif\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}"; // eslint-disable-line | ||
var MeshPhongMaterial = /*#__PURE__*/function (_MeshBasicMaterial) { | ||
_inherits(MeshPhongMaterial, _MeshBasicMaterial); | ||
var _super = _createSuper(MeshPhongMaterial); | ||
function MeshPhongMaterial(props) { | ||
var _this; | ||
_classCallCheck(this, MeshPhongMaterial); | ||
_this = _super.call(this, _objectSpread2({ | ||
vertexShader: vert$1, | ||
fragmentShader: frag$1, | ||
emissive: 'black', | ||
specular: '#111111', | ||
shininess: 30, | ||
bumpScale: 1, | ||
doubleSide: false | ||
}, props)); | ||
var _ref = props || {}, | ||
specularMap = _ref.specularMap, | ||
bumpMap = _ref.bumpMap, | ||
doubleSide = _ref.doubleSide; | ||
_this.setSpecularMap(specularMap); | ||
_this.setBumpMap(bumpMap); | ||
_this.setDoubleSide(doubleSide); | ||
return _this; | ||
} | ||
_createClass(MeshPhongMaterial, [{ | ||
key: "setAttribute", | ||
value: function setAttribute(name, value) { | ||
// @ts-ignore | ||
_get(_getPrototypeOf(MeshPhongMaterial.prototype), "setAttribute", this).call(this, name, value); | ||
if (name === 'specularMap') { | ||
this.setSpecularMap(value); | ||
} else if (name === 'bumpMap') { | ||
this.setBumpMap(value); | ||
} else if (name === 'doubleSide') { | ||
this.setDoubleSide(value); | ||
} | ||
} | ||
}, { | ||
key: "setSpecularMap", | ||
value: function setSpecularMap(map) { | ||
this.defines.USE_SPECULARMAP = !!map; | ||
this.addTexture(map, 'specular-map'); | ||
} | ||
}, { | ||
key: "setBumpMap", | ||
value: function setBumpMap(map) { | ||
this.defines.USE_BUMPMAP = !!map; | ||
this.addTexture(map, 'bump-map'); | ||
} | ||
}, { | ||
key: "setDoubleSide", | ||
value: function setDoubleSide(enabled) { | ||
this.defines.USE_DOUBLESIDE = enabled; | ||
} | ||
}, { | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
// vec3 u_Emissive; | ||
// float u_Shininess; | ||
// vec3 u_Specular; | ||
// vec3 u_AmbientLightColor; | ||
return 4 + 4 + 4; | ||
} | ||
}]); | ||
return MeshPhongMaterial; | ||
}(MeshBasicMaterial); | ||
var _excluded = ["style"]; | ||
var DirectionalLight = /*#__PURE__*/function (_Light) { | ||
_inherits(DirectionalLight, _Light); | ||
var _super = _createSuper(DirectionalLight); | ||
function DirectionalLight() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
style = _ref.style, | ||
rest = _objectWithoutProperties(_ref, _excluded); | ||
_classCallCheck(this, DirectionalLight); | ||
return _super.call(this, _objectSpread2({ | ||
style: _objectSpread2({ | ||
direction: fromValues(0, -1, 0) | ||
}, style) | ||
}, rest)); | ||
} | ||
_createClass(DirectionalLight, [{ | ||
key: "getUniformWordCount", | ||
value: function getUniformWordCount() { | ||
return 4 + 4; | ||
} | ||
}]); | ||
return DirectionalLight; | ||
}(gPluginWebglRenderer.Light); | ||
// globalContainer.register(CubeUpdater); | ||
@@ -594,2 +1385,8 @@ // globalContainer.register(SphereUpdater); | ||
Object.defineProperty(exports, 'FogType', { | ||
enumerable: true, | ||
get: function () { | ||
return gPluginWebglRenderer.FogType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'Mesh', { | ||
@@ -601,5 +1398,22 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'Sampler', { | ||
enumerable: true, | ||
get: function () { | ||
return gPluginWebglRenderer.Sampler; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'Texture2D', { | ||
enumerable: true, | ||
get: function () { | ||
return gPluginWebglRenderer.Texture2D; | ||
} | ||
}); | ||
exports.CubeGeometry = CubeGeometry; | ||
exports.DirectionalLight = DirectionalLight; | ||
exports.MeshBasicMaterial = MeshBasicMaterial; | ||
exports.MeshPhongMaterial = MeshPhongMaterial; | ||
exports.Plugin = Plugin; | ||
exports.ProceduralGeometry = ProceduralGeometry; | ||
exports.SphereGeometry = SphereGeometry; | ||
exports.TorusGeometry = TorusGeometry; | ||
exports.containerModule = containerModule; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mana-syringe"),require("@antv/g-plugin-webgl-renderer")):"function"==typeof define&&define.amd?define(["exports","mana-syringe","@antv/g-plugin-webgl-renderer"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).G=e.G||{},e.G["3D"]={}),e.window.G.ManaSyringe,e.window.G.WebGL.WebGLRenderer)}(this,(function(e,t,n){"use strict";function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;arguments.length>t;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){c(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;t.length>n;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function u(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function c(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&v(e,t)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function v(e,t){return v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},v(e,t)}function s(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function y(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=f(e);if(t){var o=f(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}var d="undefined"!=typeof Float32Array?Float32Array:Array;function _(){var e=new d(3);return d!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function p(e,t,n){var r=new d(3);return r[0]=e,r[1]=t,r[2]=n,r}function b(e,t,n,r){var o=t[0],i=t[1],a=t[2];return e[0]=o+r*(n[0]-o),e[1]=i+r*(n[1]-i),e[2]=a+r*(n[2]-a),e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});var h,g=function(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e},P=(h=_(),4/64),m=function(e){l(r,e);var t=y(r);function r(e){var n;return i(this,r),(n=t.call(this)).props=void 0,n.props=o(o({},e),{},{widthSegments:1,heightSegments:1,depthSegments:1}),n}return u(r,[{key:"init",value:function(){var e=this.buildAttributes([this.props]),t=e.positions,r=e.normals,o=e.uvs;this.setIndices(new Uint32Array(e.indices)),this.vertexCount=36,this.setVertexBuffer({bufferIndex:1,byteStride:12,frequency:1,attributes:[{format:n.Format.F32_RGB,bufferByteOffset:0,location:10}],data:Float32Array.from(t)}),this.setVertexBuffer({bufferIndex:2,byteStride:12,frequency:1,attributes:[{format:n.Format.F32_RGB,bufferByteOffset:0,location:11}],data:Float32Array.from(r)}),this.setVertexBuffer({bufferIndex:3,byteStride:8,frequency:1,attributes:[{format:n.Format.F32_RG,bufferByteOffset:0,location:12}],data:Float32Array.from(o)})}},{key:"updateAttribute",value:function(e,t,n){if("width"===e||"height"===e||"depth"===e){var r=this.buildAttributes([this.props]);this.updateVertexBuffer(1,10,n,new Uint8Array(new Float32Array(r.positions).buffer))}}},{key:"buildAttributes",value:function(e){var t=[],n=[],r=[],o=[],i=0;return e.forEach((function(e){var a=e.widthSegments,u=e.heightSegments,c=e.depthSegments,l=e.height,f=e.width,v=e.depth,s=void 0===a?1:a,y=void 0===u?1:u,d=void 0===c?1:c,h=(void 0===f?0:f)/2,m=(void 0===l?0:l)/2,S=(void 0===v?0:v)/2,k=[p(-h,-m,S),p(h,-m,S),p(h,m,S),p(-h,m,S),p(h,-m,-S),p(-h,-m,-S),p(-h,m,-S),p(h,m,-S)],O=[[0,3,1],[4,7,5],[1,4,0],[3,6,2],[1,2,4],[5,6,0]],M=[[0,0,1],[0,0,-1],[0,-1,0],[0,1,0],[1,0,0],[-1,0,0]],C=1,x=2,w=3,j=4,A=5,R=[],U=[],E=[],F=[],G=0,L=function(e,t,n){var r,o,a,u,c,l,f;for(a=0;t>=a;a++)for(u=0;n>=u;u++){var v=_(),s=_(),y=_(),d=_();b(v,k[O[e][0]],k[O[e][1]],a/t),b(s,k[O[e][0]],k[O[e][2]],u/n),g(y,s,k[O[e][0]]),(c=d)[0]=(l=v)[0]+(f=y)[0],c[1]=l[1]+f[1],c[2]=l[2]+f[2],r=a/t,o=u/n,R.push(d[0],d[1],d[2]),U.push(M[e][0],M[e][1],M[e][2]),E.push(r,o),r=.875*(r/=3)+P,o=.875*(o/=3)+P,r+=e%3/3,o+=Math.floor(e/3)/3,t>a&&n>u&&(F.push(G+n+1+i,G+1+i,G+i),F.push(G+n+1+i,G+n+2+i,G+1+i)),G++}};L(0,s,y),L(C,s,y),L(x,s,d),L(w,s,d),L(j,d,y),L(A,d,y),i+=24,t.push.apply(t,R),n.push.apply(n,U),r.push.apply(r,E),o.push.apply(o,F)})),{indices:o,positions:t,normals:n,uvs:r}}}]),r}(n.Geometry),S=function(e){l(n,e);var t=y(n);function n(e){var r;return i(this,n),(r=t.call(this)).map=void 0,r.defines={USE_UV:!0,USE_MAP:!0},r.map=null==e?void 0:e.map,r.vertexShader="#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n}",r.fragmentShader="#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n}",r}return n}(n.Material),k=t.Module((function(e){})),O=function(){function e(){i(this,e)}return u(e,[{key:"init",value:function(e){e.load(k,!0)}},{key:"destroy",value:function(e){}}]),e}();Object.defineProperty(e,"Mesh",{enumerable:!0,get:function(){return n.Mesh}}),e.CubeGeometry=m,e.MeshBasicMaterial=S,e.Plugin=O,e.containerModule=k,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mana-syringe"),require("@antv/g-plugin-webgl-renderer")):"function"==typeof define&&define.amd?define(["exports","mana-syringe","@antv/g-plugin-webgl-renderer"],e):e(((n="undefined"!=typeof globalThis?globalThis:n||self).G=n.G||{},n.G["3D"]={}),n.window.G.ManaSyringe,n.window.G.WebGL.WebGLRenderer)}(this,(function(n,e,t){"use strict";function i(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),t.push.apply(t,i)}return t}function o(n){for(var e=1;arguments.length>e;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?i(Object(t),!0).forEach((function(e){l(n,e,t[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))}))}return n}function r(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function a(n,e){for(var t=0;e.length>t;t++){var i=e[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}function c(n,e,t){return e&&a(n.prototype,e),t&&a(n,t),n}function l(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function f(n,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&d(n,e)}function u(n){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},u(n)}function d(n,e){return d=Object.setPrototypeOf||function(n,e){return n.__proto__=e,n},d(n,e)}function s(n,e){if(null==n)return{};var t,i,o=function(n,e){if(null==n)return{};var t,i,o={},r=Object.keys(n);for(i=0;r.length>i;i++)0>e.indexOf(t=r[i])&&(o[t]=n[t]);return o}(n,e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);for(i=0;r.length>i;i++)0>e.indexOf(t=r[i])&&Object.prototype.propertyIsEnumerable.call(n,t)&&(o[t]=n[t])}return o}function v(n,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(n){if(void 0===n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}(n)}function _(n){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(n){return!1}}();return function(){var t,i=u(n);if(e){var o=u(this).constructor;t=Reflect.construct(i,arguments,o)}else t=i.apply(this,arguments);return v(this,t)}}function g(n,e){for(;!Object.prototype.hasOwnProperty.call(n,e)&&null!==(n=u(n)););return n}function p(){return p="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(n,e,t){var i=g(n,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(3>arguments.length?n:t):o.value}},p.apply(this,arguments)}var h="undefined"!=typeof Float32Array?Float32Array:Array;function y(){var n=new h(16);return h!=Float32Array&&(n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[11]=0,n[12]=0,n[13]=0,n[14]=0),n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function m(){var n=new h(3);return h!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n}function S(n,e,t){var i=new h(3);return i[0]=n,i[1]=e,i[2]=t,i}function P(n,e,t,i){var o=e[0],r=e[1],a=e[2];return n[0]=o+i*(t[0]-o),n[1]=r+i*(t[1]-r),n[2]=a+i*(t[2]-a),n}Math.hypot||(Math.hypot=function(){for(var n=0,e=arguments.length;e--;)n+=arguments[e]*arguments[e];return Math.sqrt(n)});var M,b=function(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n};M=m();function L(){var n=new h(4);return h!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0,n[3]=0),n}function E(n,e,t){var i=e[0],o=e[1],r=e[2],a=e[3];return n[0]=t[0]*i+t[4]*o+t[8]*r+t[12]*a,n[1]=t[1]*i+t[5]*o+t[9]*r+t[13]*a,n[2]=t[2]*i+t[6]*o+t[10]*r+t[14]*a,n[3]=t[3]*i+t[7]*o+t[11]*r+t[15]*a,n}var x;!function(){var n=L()}();(x=n.ProceduralGeometryAttributeLocation||(n.ProceduralGeometryAttributeLocation={}))[x.POSITION=1]="POSITION",x[x.NORMAL=2]="NORMAL",x[x.UV=3]="UV",x[x.MAX=4]="MAX";var I=function(e){f(o,e);var i=_(o);function o(){return r(this,o),i.apply(this,arguments)}return c(o,[{key:"applyMat4",value:function(e){for(var t=this.vertexBuffers[n.ProceduralGeometryAttributeLocation.POSITION],i=L(),o=0;t.byteLength/4>o;o+=3)i[0]=t[o],i[1]=t[o+1],i[2]=t[o+2],i[3]=1,E(i,i,e),t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2];var r,a,c=this.vertexBuffers[n.ProceduralGeometryAttributeLocation.NORMAL],l=((r=y())[0]=(a=e)[0],r[1]=a[1],r[2]=a[2],r[3]=a[3],r[4]=a[4],r[5]=a[5],r[6]=a[6],r[7]=a[7],r[8]=a[8],r[9]=a[9],r[10]=a[10],r[11]=a[11],r[12]=a[12],r[13]=a[13],r[14]=a[14],r[15]=a[15],r);!function(n,e){var t=e[0],i=e[1],o=e[2],r=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],d=e[9],s=e[10],v=e[11],_=e[12],g=e[13],p=e[14],h=e[15],y=t*c-i*a,m=t*l-o*a,S=t*f-r*a,P=i*l-o*c,M=i*f-r*c,b=o*f-r*l,L=u*g-d*_,E=u*p-s*_,x=u*h-v*_,I=d*p-s*g,C=d*h-v*g,F=s*h-v*p,O=y*F-m*C+S*I+P*x-M*E+b*L;O&&(n[0]=(c*F-l*C+f*I)*(O=1/O),n[1]=(o*C-i*F-r*I)*O,n[2]=(g*b-p*M+h*P)*O,n[3]=(s*M-d*b-v*P)*O,n[4]=(l*x-a*F-f*E)*O,n[5]=(t*F-o*x+r*E)*O,n[6]=(p*S-_*b-h*m)*O,n[7]=(u*b-s*S+v*m)*O,n[8]=(a*C-c*x+f*L)*O,n[9]=(i*x-t*C-r*L)*O,n[10]=(_*M-g*S+h*y)*O,n[11]=(d*S-u*M-v*y)*O,n[12]=(c*E-a*I-l*L)*O,n[13]=(t*I-i*E+o*L)*O,n[14]=(g*m-_*P-p*y)*O,n[15]=(u*P-d*m+s*y)*O)}(l,l),function(n,e){if(n===e){var t=e[1],i=e[2],o=e[3],r=e[6],a=e[7],c=e[11];n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=t,n[6]=e[9],n[7]=e[13],n[8]=i,n[9]=r,n[11]=e[14],n[12]=o,n[13]=a,n[14]=c}else n[0]=e[0],n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=e[1],n[5]=e[5],n[6]=e[9],n[7]=e[13],n[8]=e[2],n[9]=e[6],n[10]=e[10],n[11]=e[14],n[12]=e[3],n[13]=e[7],n[14]=e[11],n[15]=e[15]}(l,l);for(var f=0;c.byteLength/4>f;f+=3)i[0]=c[f],i[1]=c[f+1],i[2]=c[f+2],i[3]=1,E(i,i,l),c[f]=i[0],c[f+1]=i[1],c[f+2]=i[2]}},{key:"getBoundingBox",value:function(){}},{key:"build",value:function(e){var i,o,r=this.createTopology(e),a=r.positions,c=r.normals,l=r.uvs,f=r.vertexCountPerInstance;this.setIndices(new Uint32Array(r.indices)),this.vertexCount=f,this.setVertexBuffer({bufferIndex:n.ProceduralGeometryAttributeLocation.POSITION,byteStride:12,frequency:1,attributes:[{format:t.Format.F32_RGB,bufferByteOffset:0,location:10}],data:Float32Array.from(a)}),this.setVertexBuffer({bufferIndex:n.ProceduralGeometryAttributeLocation.NORMAL,byteStride:12,frequency:1,attributes:[{format:t.Format.F32_RGB,bufferByteOffset:0,location:11}],data:Float32Array.from(c)}),this.setVertexBuffer({bufferIndex:n.ProceduralGeometryAttributeLocation.UV,byteStride:8,frequency:1,attributes:[{format:t.Format.F32_RG,bufferByteOffset:0,location:12}],data:Float32Array.from(l)}),this.applyMat4((i=y(),o=S(1,-1,1),i[0]=o[0],i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=o[1],i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=o[2],i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i))}}]),o}(t.BufferGeometry),C=4/64,F=function(n){f(t,n);var e=_(t);function t(){return r(this,t),e.apply(this,arguments)}return c(t,[{key:"createTopology",value:function(n){var e=[],t=[],i=[],o=[],r=[],a=0,c=0;return n.map((function(n){return n.style})).forEach((function(n){var l=n.widthSegments,f=n.heightSegments,u=n.depthSegments,d=n.height,s=n.width,v=n.depth,_=void 0===l?1:l,g=void 0===f?1:f,p=void 0===u?1:u,h=(void 0===s?0:s)/2,y=(void 0===d?0:d)/2,M=(void 0===v?0:v)/2,L=[S(-h,-y,M),S(h,-y,M),S(h,y,M),S(-h,y,M),S(h,-y,-M),S(-h,-y,-M),S(-h,y,-M),S(h,y,-M)],E=[[0,1,3],[4,5,7],[3,2,6],[1,0,4],[1,4,2],[5,0,6]],x=[[0,0,1],[0,0,-1],[0,1,0],[0,-1,0],[1,0,0],[-1,0,0]],I=1,F=2,O=3,D=4,R=5,U=[],k=[],w=[],A=[],G=[],B=0,N=function(n,e,t){var i,o,r,c,l,f,u;for(r=0;e>=r;r++)for(c=0;t>=c;c++){var d=m(),s=m(),v=m(),_=m();P(d,L[E[n][0]],L[E[n][1]],r/e),P(s,L[E[n][0]],L[E[n][2]],c/t),b(v,s,L[E[n][0]]),(l=_)[0]=(f=d)[0]+(u=v)[0],l[1]=f[1]+u[1],l[2]=f[2]+u[2],i=r/e,o=c/t,U.push(_[0],_[1],_[2]),k.push(x[n][0],x[n][1],x[n][2]),w.push(i,1-o),i=.875*(i/=3)+C,o=.875*(o/=3)+C,A.push(i+=n%3/3,1-(o+=Math.floor(n/3)/3)),e>r&&t>c&&(G.push(B+t+1+a,B+1+a,B+a),G.push(B+t+1+a,B+t+2+a,B+1+a)),B++}};N(0,_,g),N(I,_,g),N(F,_,p),N(O,_,p),N(D,p,g),N(R,p,g),a+=c=G.length,e.push.apply(e,U),t.push.apply(t,k),i.push.apply(i,w),o.push.apply(o,A),r.push.apply(r,G)})),{indices:r,positions:e,normals:t,uvs:i,uvs1:o,vertexCountPerInstance:c}}}]),t}(I),O=function(n){f(t,n);var e=_(t);function t(){return r(this,t),e.apply(this,arguments)}return c(t,[{key:"createTopology",value:function(n){var e,t,i,o,r,a,c,l,f,u,d,s,v,_,g=[],p=[],h=[],y=[],m=0,S=0;return n.map((function(n){return n.style})).forEach((function(n){var P=n.radius,M=void 0===P?.5:P,b=n.latitudeBands,L=void 0===b?16:b,E=n.longitudeBands,x=void 0===E?16:E,I=[],C=[],F=[],O=[];for(t=0;L>=t;t++)for(o=Math.sin(i=t*Math.PI/L),r=Math.cos(i),e=0;x>=e;e++)c=Math.sin(a=2*e*Math.PI/x-Math.PI/2),v=1-e/x,_=1-t/L,I.push((u=Math.cos(a)*o)*M,(d=r)*M,(s=c*o)*M),C.push(u,d,s),F.push(v,1-_);for(t=0;L>t;++t)for(e=0;x>e;++e)O.push((l=t*(x+1)+e)+1+m,(f=l+x+1)+m,l+m),O.push(l+1+m,f+1+m,f+m);m+=S=O.length,g.push.apply(g,I),p.push.apply(p,C),h.push.apply(h,F),y.push.apply(y,O)})),{indices:y,positions:g,normals:p,uvs:h,uvs1:h,vertexCountPerInstance:S}}}]),t}(I),D=function(n){f(t,n);var e=_(t);function t(){return r(this,t),e.apply(this,arguments)}return c(t,[{key:"createTopology",value:function(n){var e,t,i,o,r,a,c,l,f,u,d=[],s=[],v=[],_=[],g=0,p=0;return n.map((function(n){return n.style})).forEach((function(n){var h=n.tubeRadius,y=n.ringRadius,m=n.segments,S=void 0===m?30:m,P=n.sides,M=void 0===P?20:P,b=void 0===h?.2:h,L=void 0===y?.3:y,E=[],x=[],I=[],C=[];for(f=0;M>=f;f++)for(u=0;S>=u;u++)if(e=Math.cos(2*Math.PI*u/S)*(L+b*Math.cos(2*Math.PI*f/M)),t=Math.sin(2*Math.PI*f/M)*b,i=Math.sin(2*Math.PI*u/S)*(L+b*Math.cos(2*Math.PI*f/M)),o=Math.cos(2*Math.PI*u/S)*Math.cos(2*Math.PI*f/M),r=Math.sin(2*Math.PI*f/M),a=Math.sin(2*Math.PI*u/S)*Math.cos(2*Math.PI*f/M),c=f/M,l=1-u/S,E.push(e,t,i),x.push(o,r,a),I.push(c,1-l),M>f&&S>u){var F,O,D;D=(f+1)*(S+1)+(u+1),C.push(f*(S+1)+u+g,(F=(f+1)*(S+1)+u)+g,(O=f*(S+1)+(u+1))+g),C.push(F+g,D+g,O+g)}g+=p=C.length,d.push.apply(d,E),s.push.apply(s,x),v.push.apply(v,I),_.push.apply(_,C)})),{indices:_,positions:d,normals:s,uvs:v,uvs1:v,vertexCountPerInstance:p}}}]),t}(I),R=function(n){f(t,n);var e=_(t);function t(n){var i;r(this,t),(i=e.call(this,o({vertexShader:"#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n gl_Position = project(vec4(a_Position, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}",fragmentShader:"#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}",cullMode:2},n))).defines={USE_UV:!0,USE_MAP:!1,USE_WIREFRAME:!1,USE_FOG:!1};var a=n||{},c=a.wireframe;return i.setMap(a.map),i.setWireframe(c),i.setFog(),i}return c(t,[{key:"getUniformWordCount",value:function(){return 12}},{key:"setAttribute",value:function(n,e){p(u(t.prototype),"setAttribute",this).call(this,n,e),"map"===n?this.setMap(e):"fogType"!==n&&"fogColor"!==n&&"fogStart"!==n&&"fogEnd"!==n&&"fogDensity"!==n||this.setFog()}},{key:"setMap",value:function(n){this.defines.USE_MAP=!!n,this.addTexture(n,"map")}},{key:"setWireframe",value:function(n){this.defines.USE_WIREFRAME=!!n}},{key:"setFog",value:function(){this.defines.USE_FOG=!!this.props.fogType}}]),t}(t.Material),U=function(n){f(t,n);var e=_(t);function t(n){var i;r(this,t),i=e.call(this,o({vertexShader:"#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nlayout(location = 0) attribute vec4 a_ModelMatrix0;\nlayout(location = 1) attribute vec4 a_ModelMatrix1;\nlayout(location = 2) attribute vec4 a_ModelMatrix2;\nlayout(location = 3) attribute vec4 a_ModelMatrix3;\nlayout(location = 4) attribute vec4 a_Color;\nlayout(location = 5) attribute vec4 a_StrokeColor;\nlayout(location = 6) attribute vec4 a_StylePacked1;\nlayout(location = 7) attribute vec4 a_StylePacked2;\nlayout(location = 8) attribute vec4 a_PickingColor;\nlayout(location = 9) attribute vec2 a_Anchor;\n// layout(location = {AttributeLocation.a_Uv}) attribute vec2 a_Uv;\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = 10) attribute vec3 a_Position;\nlayout(location = 11) attribute vec3 a_Normal;\n\n#ifdef USE_UV\n layout(location = 12) attribute vec2 a_Uv;\n varying vec2 v_Uv;\n#endif\n\n#ifdef USE_WIREFRAME\n layout(location = 13) attribute vec3 a_Barycentric;\n varying vec3 v_Barycentric;\n#endif\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n\n vec4 position = vec4(a_Position, 1.0);\n\n gl_Position = project(position, u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n\n vec4 mvPosition = u_ViewMatrix * u_ModelMatrix * position;\n v_ViewPosition = - mvPosition.xyz;\n\n // v_ViewPosition = vec3(mvPosition) / mvPosition.w;\n\n mat3 normalWorld = mat3(transpose(inverse(u_ViewMatrix * u_ModelMatrix)));\n v_Normal = normalize(normalWorld * a_Normal);\n\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n #ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n}",fragmentShader:"#define GLSLIFY 1\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n #define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n}\n\nstruct DirectionalLight {\n vec3 direction;\n float intensity;\n vec3 color;\n};\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n bool u_IsOrtho;\n};\nlayout(std140) uniform ub_MaterialParams {\n vec3 u_Emissive;\n float u_Shininess;\n vec3 u_Specular;\n vec3 u_AmbientLightColor;\n\n #ifdef USE_FOG\n vec4 u_FogInfos;\n vec3 u_FogColor;\n #endif\n\n #ifdef USE_LIGHT\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n #endif\n #endif\n\n #ifdef USE_BUMPMAP\n float u_BumpScale;\n #endif\n};\n#ifdef USE_LIGHT\n void getDirectionalLightInfo(\n const in DirectionalLight directionalLight, \n const in GeometricContext geometry,\n out IncidentLight light\n ) {\n light.color = directionalLight.color * directionalLight.intensity;\n light.direction = normalize(directionalLight.direction);\n light.visible = true;\n }\n#endif\n\nvarying vec4 v_PickingResult;\nvarying vec4 v_Color;\nvarying vec4 v_StrokeColor;\nvarying vec4 v_StylePacked1;\nvarying vec4 v_StylePacked2;\n#ifdef USE_UV\n varying vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n#ifdef USE_BUMPMAP\n uniform sampler2D u_BumpMap;\n\n // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen\n // http://api.unrealengine.com/attachments/Engine/Rendering/LightingAndShadows/BumpMappingWithoutTangentSpace/mm_sfgrad_bump.pdf\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( v_Uv );\n vec2 dSTdy = dFdy( v_Uv );\n\n float Hll = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv ).x;\n float dBx = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdx ).x - Hll;\n float dBy = u_BumpScale * texture(SAMPLER_2D(u_BumpMap), v_Uv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\n // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\n\n vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n vec3 vN = surf_norm;\t\t// normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n#ifdef USE_SPECULARMAP\n uniform sampler2D u_SpecularMap;\n#endif\nvec3 BRDF_Lambert(const in vec3 diffuseColor) {\n return RECIPROCAL_PI * diffuseColor;\n}\n\nvec3 F_Schlick(\n const in vec3 f0,\n const in float f90,\n const in float dotVH\n) {\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotVH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\n\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n}\n\nfloat D_BlinnPhong(\n const in float shininess,\n const in float dotNH\n) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\n\nvec3 BRDF_BlinnPhong(\n const in vec3 lightDir,\n const in vec3 viewDir,\n const in vec3 normal,\n const in vec3 specularColor,\n const in float shininess\n) {\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * ( G * D );\n}\n\n// uniform vec3 u_WireframeLineColor;\n// uniform float u_WireframeLineWidth;\n\n#ifdef USE_WIREFRAME\n varying vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\n#ifdef USE_FOG\n #define FOGMODE_NONE 0.\n #define FOGMODE_EXP 1.\n #define FOGMODE_EXP2 2.\n #define FOGMODE_LINEAR 3.\n\n float dBlendModeFogFactor = 1.0;\n\n vec3 addFog(vec3 color) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor;\n float fogStart = u_FogInfos.y;\n float fogEnd = u_FogInfos.z;\n float fogDensity = u_FogInfos.w;\n\n if (u_FogInfos.x == FOGMODE_NONE) {\n fogFactor = 1.0;\n } else if (u_FogInfos.x == FOGMODE_EXP) {\n fogFactor = exp(-depth * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_EXP2) {\n fogFactor = exp(-depth * depth * fogDensity * fogDensity);\n } else if (u_FogInfos.x == FOGMODE_LINEAR) {\n fogFactor = (fogEnd - depth) / (fogEnd - fogStart);\n }\n\n fogFactor = clamp(fogFactor, 0.0, 1.0);\n return mix(u_FogColor * dBlendModeFogFactor, color, fogFactor);\n }\n#endif\n\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\n\nvoid RE_Direct_BlinnPhong(\n const in IncidentLight directLight,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n float dotNL = saturate(dot(geometry.normal, directLight.direction));\n vec3 irradiance = dotNL * directLight.color;\n\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\n\nvoid RE_IndirectDiffuse_BlinnPhong(\n const in vec3 irradiance,\n const in GeometricContext geometry,\n const in BlinnPhongMaterial material,\n inout ReflectedLight reflectedLight\n) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\n\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n\nvarying vec3 v_ViewPosition;\nvarying vec3 v_Normal;\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\n\ngbuf_picking = vec4(v_PickingResult.rgb, 1.0);\n\nif (u_Visible < 1.0) {\n discard;\n}\n #ifdef USE_MAP\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n#endif\n float specularStrength = 1.0;\n\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture(SAMPLER_2D(u_SpecularMap), v_Uv);\n specularStrength = texelSpecular.r;\n#endif\n\n float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n vec3 normal = normalize(v_Normal);\n #ifdef USE_DOUBLESIDE\n\t\tnormal = normal * faceDirection;\n\t#endif\n\n // #ifdef USE_TANGENT\n // vec3 tangent = normalize( vTangent );\n // vec3 bitangent = normalize( vBitangent );\n\n // #ifdef DOUBLE_SIDED\n // tangent = tangent * faceDirection;\n // bitangent = bitangent * faceDirection;\n // #endif\n // #endif\n\n #ifdef USE_BUMPMAP\n\tnormal = perturbNormalArb( - v_ViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif\n\n gl_FragColor = u_Color;\n gl_FragColor.a = gl_FragColor.a * u_Opacity;\n\n #ifdef USE_LIGHT\n vec4 diffuseColor = gl_FragColor;\n ReflectedLight reflectedLight = ReflectedLight(vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ));\n vec3 totalEmissiveRadiance = u_Emissive;\n\n BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = u_Specular;\nmaterial.specularShininess = u_Shininess;\nmaterial.specularStrength = specularStrength;\n\n GeometricContext geometry;\n geometry.position = - v_ViewPosition;\n geometry.normal = normal;\n geometry.viewDir = u_IsOrtho ? vec3(0, 0, 1) : normalize(v_ViewPosition);\n\n IncidentLight directLight;\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n directionalLight = directionalLights[ i ];\n\n getDirectionalLightInfo( directionalLight, geometry, directLight );\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance(u_AmbientLightColor);\n\n // irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n // #if ( NUM_HEMI_LIGHTS > 0 )\n // #pragma unroll_loop_start\n // for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n // irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n // }\n // #pragma unroll_loop_end\n // #endif\n #endif\n\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n #endif\n\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n #endif\n\n vec3 outgoingLight = reflectedLight.directDiffuse +\n reflectedLight.indirectDiffuse + \n reflectedLight.directSpecular + \n reflectedLight.indirectSpecular + \n totalEmissiveRadiance;\n\n gl_FragColor = vec4(outgoingLight, diffuseColor.a);\n #endif\n\n #ifdef USE_FOG\n gl_FragColor.rgb = addFog(gl_FragColor.rgb);\n #endif\n\n #ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.);\n vec3 wireframeAoColor = vec3(1.);\n vec3 color;\n // draw wireframe with ao\n color = mix(gl_FragColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n gl_FragColor.xyz = color;\n #endif\n}",emissive:"black",specular:"#111111",shininess:30,bumpScale:1,doubleSide:!1},n));var a=n||{},c=a.bumpMap,l=a.doubleSide;return i.setSpecularMap(a.specularMap),i.setBumpMap(c),i.setDoubleSide(l),i}return c(t,[{key:"setAttribute",value:function(n,e){p(u(t.prototype),"setAttribute",this).call(this,n,e),"specularMap"===n?this.setSpecularMap(e):"bumpMap"===n?this.setBumpMap(e):"doubleSide"===n&&this.setDoubleSide(e)}},{key:"setSpecularMap",value:function(n){this.defines.USE_SPECULARMAP=!!n,this.addTexture(n,"specular-map")}},{key:"setBumpMap",value:function(n){this.defines.USE_BUMPMAP=!!n,this.addTexture(n,"bump-map")}},{key:"setDoubleSide",value:function(n){this.defines.USE_DOUBLESIDE=n}},{key:"getUniformWordCount",value:function(){return 12}}]),t}(R),k=["style"],w=function(n){f(t,n);var e=_(t);function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=n.style,a=s(n,k);return r(this,t),e.call(this,o({style:o({direction:S(0,-1,0)},i)},a))}return c(t,[{key:"getUniformWordCount",value:function(){return 8}}]),t}(t.Light),A=e.Module((function(n){})),G=function(){function n(){r(this,n)}return c(n,[{key:"init",value:function(n){n.load(A,!0)}},{key:"destroy",value:function(n){}}]),n}();Object.defineProperty(n,"FogType",{enumerable:!0,get:function(){return t.FogType}}),Object.defineProperty(n,"Mesh",{enumerable:!0,get:function(){return t.Mesh}}),Object.defineProperty(n,"Sampler",{enumerable:!0,get:function(){return t.Sampler}}),Object.defineProperty(n,"Texture2D",{enumerable:!0,get:function(){return t.Texture2D}}),n.CubeGeometry=F,n.DirectionalLight=w,n.MeshBasicMaterial=R,n.MeshPhongMaterial=U,n.Plugin=G,n.ProceduralGeometry=I,n.SphereGeometry=O,n.TorusGeometry=D,n.containerModule=A,Object.defineProperty(n,"__esModule",{value:!0})})); |
export * from './MeshBasicMaterial'; | ||
export * from './MeshPhongMaterial'; |
@@ -1,4 +0,11 @@ | ||
import { Material } from '@antv/g-plugin-webgl-renderer'; | ||
export interface MeshBasicMaterialProps { | ||
map?: string; | ||
import { Material, Texture2D, MaterialProps } from '@antv/g-plugin-webgl-renderer'; | ||
export interface MeshBasicMaterialProps extends MaterialProps { | ||
/** | ||
* color map, will override fill color | ||
*/ | ||
map?: string | TexImageSource | Texture2D; | ||
/** | ||
* AO map | ||
*/ | ||
aoMap?: string | TexImageSource | Texture2D; | ||
} | ||
@@ -9,5 +16,9 @@ /** | ||
*/ | ||
export declare class MeshBasicMaterial extends Material { | ||
map: string; | ||
export declare class MeshBasicMaterial extends Material<MeshBasicMaterialProps> { | ||
constructor(props?: MeshBasicMaterialProps); | ||
getUniformWordCount(): number; | ||
protected setAttribute<Key extends keyof MeshBasicMaterialProps>(name: Key, value: MeshBasicMaterialProps[Key]): void; | ||
private setMap; | ||
private setWireframe; | ||
private setFog; | ||
} |
{ | ||
"name": "@antv/g-plugin-3d", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Provide 3D extension for G", | ||
@@ -40,4 +40,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@antv/g-plugin-webgl-renderer": "^1.0.7", | ||
"@antv/g-shader-components": "^1.0.2", | ||
"@antv/g-plugin-webgl-renderer": "^1.0.8", | ||
"@antv/g-shader-components": "^1.0.3", | ||
"@antv/util": "^2.0.13", | ||
@@ -56,3 +56,3 @@ "tslib": "^2.3.1" | ||
}, | ||
"gitHead": "039cea4e9baf6988a7d6105bb3a907ed816a2fd9" | ||
"gitHead": "dce0982c006f8205d73b6537ef620b15218a47d0" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
233616
27
4164
16