@antv/g-webgpu-raytracer
Version:
A simple ray tracer implemented with WebGPU
66 lines (46 loc) • 3.09 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
import { Buffer } from './Buffer';
export var MeshBuffer = /*#__PURE__*/function (_Buffer) {
_inherits(MeshBuffer, _Buffer);
var _super = _createSuper(MeshBuffer);
function MeshBuffer(length) {
_classCallCheck(this, MeshBuffer);
return _super.call(this, 2, length);
}
_createClass(MeshBuffer, [{
key: "append",
value: function append(meshData) {
var _meshData$slabCount, _meshData$slabOffset, _meshData$specularExp;
// padding required: https://twitter.com/9ballsyndrome/status/1178039885090848770
// under std430 layout, a struct in an array use the largest alignment of its member.
// int face_count;
this.appendI(meshData.faceCount); // int offset;
this.appendI(meshData.vertexOffset); // int slab_count
this.appendI((_meshData$slabCount = meshData.slabCount) !== null && _meshData$slabCount !== void 0 ? _meshData$slabCount : 0); // int slab_offset;
this.appendI((_meshData$slabOffset = meshData.slabOffset) !== null && _meshData$slabOffset !== void 0 ? _meshData$slabOffset : 0); // alpha
this.appendF((_meshData$specularExp = meshData.specularExponent) !== null && _meshData$specularExp !== void 0 ? _meshData$specularExp : 100); // paddings
this.pad(3); // vec3 color;
this.appendF(meshData.diffuseColor[0] || 0);
this.appendF(meshData.diffuseColor[1] || 0);
this.appendF(meshData.diffuseColor[2] || 0); // padding
this.pad(1); // vec3 specular
this.appendF(meshData.specularColor[0] || 0);
this.appendF(meshData.specularColor[1] || 0);
this.appendF(meshData.specularColor[2] || 0); // padding
this.pad(1); // vec3 refraction;
this.appendF(meshData.refractionColor[0] || 0);
this.appendF(meshData.refractionColor[1] || 0);
this.appendF(meshData.refractionColor[2] || 0); // padding
this.pad(1);
}
}]);
return MeshBuffer;
}(Buffer);
MeshBuffer.bytes = 20;
//# sourceMappingURL=MeshBuffer.js.map