123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- import {
- Cartesian3,
- Check,
- defined,
- destroyObject,
- HeadingPitchRoll,
- Matrix3,
- Matrix4,
- CustomShader,
- VoxelShapeType,
- } from "@cesium/engine";
- import knockout from "../ThirdParty/knockout.js";
- function formatShaderString(str) {
- // This function:
- // A) removes whitespace lines at the beginning of the string
- // B) removes unnecessary spaces from the beginning of each line
- const lines = str.split("\n");
- let firstLineIdx;
- for (firstLineIdx = 0; firstLineIdx < lines.length; firstLineIdx++) {
- if (lines[firstLineIdx].match(/\S/)) {
- // Found the first line that's not entirely whitespace
- break;
- }
- }
- if (firstLineIdx === lines.length) {
- // All lines are empty
- return "";
- }
- let finalStr = "";
- const pattern = /^\s*/;
- const firstLine = lines[firstLineIdx];
- const spacesInFrontOfFirstLine = firstLine.match(pattern)[0].length;
- for (let i = firstLineIdx; i < lines.length; i++) {
- let line = lines[i];
- const spacesInFront = line.match(pattern)[0].length;
- if (spacesInFront >= spacesInFrontOfFirstLine) {
- line = line.slice(spacesInFrontOfFirstLine);
- }
- finalStr += `${line}\n`;
- }
- return finalStr;
- }
- /**
- * The view model for {@link VoxelInspector}.
- * @alias VoxelInspectorViewModel
- * @constructor
- *
- * @param {Scene} scene The scene instance to use.
- */
- function VoxelInspectorViewModel(scene) {
- //>>includeStart('debug', pragmas.debug);
- Check.typeOf.object("scene", scene);
- //>>includeEnd('debug');
- this._scene = scene;
- this._voxelPrimitive = undefined;
- this._customShaderCompilationRemoveCallback = undefined;
- this._definedProperties = [];
- this._getPrimitiveFunctions = [];
- this._modelMatrixReady = false;
- const that = this;
- function addProperty(options) {
- const { name, initialValue } = options;
- that._definedProperties.push(name);
- let setPrimitiveFunction = options.setPrimitiveFunction;
- if (setPrimitiveFunction === true) {
- setPrimitiveFunction = function (value) {
- that._voxelPrimitive[name] = value;
- };
- }
- let getPrimitiveFunction = options.getPrimitiveFunction;
- if (getPrimitiveFunction === true) {
- getPrimitiveFunction = function () {
- that[name] = that._voxelPrimitive[name];
- };
- }
- if (defined(getPrimitiveFunction)) {
- that._getPrimitiveFunctions.push(getPrimitiveFunction);
- }
- const knock = knockout.observable();
- knockout.defineProperty(that, name, {
- get: function () {
- return knock();
- },
- set: function (value) {
- // Convert input values to the correct type
- if (typeof initialValue === "number" && typeof value === "string") {
- value = Number(value);
- if (isNaN(value)) {
- value = initialValue;
- }
- }
- if (typeof initialValue === "boolean" && typeof value === "number") {
- value = value === 1 ? true : false;
- }
- knock(value);
- if (defined(setPrimitiveFunction) && defined(that._voxelPrimitive)) {
- setPrimitiveFunction(value);
- scene.requestRender();
- }
- },
- });
- that[name] = initialValue;
- return knock;
- }
- function getBoundSetter(boundKey, component) {
- return function (value) {
- const bound = that._voxelPrimitive[boundKey].clone();
- bound[component] = value;
- that._voxelPrimitive[boundKey] = bound;
- };
- }
- addProperty({
- name: "inspectorVisible",
- initialValue: true,
- });
- addProperty({
- name: "displayVisible",
- initialValue: false,
- });
- addProperty({
- name: "transformVisible",
- initialValue: false,
- });
- addProperty({
- name: "boundsVisible",
- initialValue: false,
- });
- addProperty({
- name: "clippingVisible",
- initialValue: false,
- });
- addProperty({
- name: "shaderVisible",
- initialValue: false,
- });
- addProperty({
- name: "shaderString",
- initialValue: "",
- getPrimitiveFunction: function () {
- const shaderString = that._voxelPrimitive.customShader.fragmentShaderText;
- that.shaderString = formatShaderString(shaderString);
- },
- });
- addProperty({
- name: "shaderCompilationMessage",
- initialValue: "",
- });
- addProperty({
- name: "shaderCompilationSuccess",
- initialValue: true,
- });
- addProperty({
- name: "depthTest",
- initialValue: false,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "show",
- initialValue: true,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "disableUpdate",
- initialValue: false,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "debugDraw",
- initialValue: false,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "jitter",
- initialValue: true,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "nearestSampling",
- initialValue: true,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "screenSpaceError",
- initialValue: 4.0,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "stepSize",
- initialValue: 1.0,
- setPrimitiveFunction: true,
- getPrimitiveFunction: true,
- });
- addProperty({
- name: "shapeIsBox",
- getPrimitiveFunction: function () {
- const shapeType = that._voxelPrimitive.shape;
- that.shapeIsBox = shapeType === VoxelShapeType.BOX;
- },
- });
- addProperty({
- name: "shapeIsEllipsoid",
- getPrimitiveFunction: function () {
- const shapeType = that._voxelPrimitive.shape;
- that.shapeIsEllipsoid = shapeType === VoxelShapeType.ELLIPSOID;
- },
- });
- addProperty({
- name: "shapeIsCylinder",
- getPrimitiveFunction: function () {
- const shapeType = that._voxelPrimitive.shape;
- that.shapeIsCylinder = shapeType === VoxelShapeType.CYLINDER;
- },
- });
- addProperty({
- name: "boundsBoxMaxX",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsBoxMaxX = that._voxelPrimitive.maxBounds.x;
- },
- });
- addProperty({
- name: "boundsBoxMinX",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsBoxMinX = that._voxelPrimitive.minBounds.x;
- },
- });
- addProperty({
- name: "boundsBoxMaxY",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsBoxMaxY = that._voxelPrimitive.maxBounds.y;
- },
- });
- addProperty({
- name: "boundsBoxMinY",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsBoxMinY = that._voxelPrimitive.minBounds.y;
- },
- });
- addProperty({
- name: "boundsBoxMaxZ",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsBoxMaxZ = that._voxelPrimitive.maxBounds.z;
- },
- });
- addProperty({
- name: "boundsBoxMinZ",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsBoxMinZ = that._voxelPrimitive.minBounds.z;
- },
- });
- addProperty({
- name: "boundsEllipsoidMaxLongitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMaxLongitude = that._voxelPrimitive.maxBounds.x;
- },
- });
- addProperty({
- name: "boundsEllipsoidMinLongitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMinLongitude = that._voxelPrimitive.minBounds.x;
- },
- });
- addProperty({
- name: "boundsEllipsoidMaxLatitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMaxLatitude = that._voxelPrimitive.maxBounds.y;
- },
- });
- addProperty({
- name: "boundsEllipsoidMinLatitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMinLatitude = that._voxelPrimitive.minBounds.y;
- },
- });
- addProperty({
- name: "boundsEllipsoidMaxHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMaxHeight = that._voxelPrimitive.maxBounds.z;
- },
- });
- addProperty({
- name: "boundsEllipsoidMinHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsEllipsoidMinHeight = that._voxelPrimitive.minBounds.z;
- },
- });
- addProperty({
- name: "boundsCylinderMaxRadius",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMaxRadius = that._voxelPrimitive.maxBounds.x;
- },
- });
- addProperty({
- name: "boundsCylinderMinRadius",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "x"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMinRadius = that._voxelPrimitive.minBounds.x;
- },
- });
- addProperty({
- name: "boundsCylinderMaxHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMaxHeight = that._voxelPrimitive.maxBounds.y;
- },
- });
- addProperty({
- name: "boundsCylinderMinHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "y"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMinHeight = that._voxelPrimitive.minBounds.y;
- },
- });
- addProperty({
- name: "boundsCylinderMaxAngle",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMaxAngle = that._voxelPrimitive.maxBounds.z;
- },
- });
- addProperty({
- name: "boundsCylinderMinAngle",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minBounds", "z"),
- getPrimitiveFunction: function () {
- that.boundsCylinderMinAngle = that._voxelPrimitive.minBounds.z;
- },
- });
- addProperty({
- name: "clippingBoxMaxX",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingBoxMaxX = that._voxelPrimitive.maxClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingBoxMinX",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingBoxMinX = that._voxelPrimitive.minClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingBoxMaxY",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingBoxMaxY = that._voxelPrimitive.maxClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingBoxMinY",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingBoxMinY = that._voxelPrimitive.minClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingBoxMaxZ",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingBoxMaxZ = that._voxelPrimitive.maxClippingBounds.z;
- },
- });
- addProperty({
- name: "clippingBoxMinZ",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingBoxMinZ = that._voxelPrimitive.minClippingBounds.z;
- },
- });
- addProperty({
- name: "clippingEllipsoidMaxLongitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMaxLongitude =
- that._voxelPrimitive.maxClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingEllipsoidMinLongitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMinLongitude =
- that._voxelPrimitive.minClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingEllipsoidMaxLatitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMaxLatitude =
- that._voxelPrimitive.maxClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingEllipsoidMinLatitude",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMinLatitude =
- that._voxelPrimitive.minClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingEllipsoidMaxHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMaxHeight =
- that._voxelPrimitive.maxClippingBounds.z;
- },
- });
- addProperty({
- name: "clippingEllipsoidMinHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingEllipsoidMinHeight =
- that._voxelPrimitive.minClippingBounds.z;
- },
- });
- addProperty({
- name: "clippingCylinderMaxRadius",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMaxRadius = that._voxelPrimitive.maxClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingCylinderMinRadius",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "x"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMinRadius = that._voxelPrimitive.minClippingBounds.x;
- },
- });
- addProperty({
- name: "clippingCylinderMaxHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMaxHeight = that._voxelPrimitive.maxClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingCylinderMinHeight",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "y"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMinHeight = that._voxelPrimitive.minClippingBounds.y;
- },
- });
- addProperty({
- name: "clippingCylinderMaxAngle",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("maxClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMaxAngle = that._voxelPrimitive.maxClippingBounds.z;
- },
- });
- addProperty({
- name: "clippingCylinderMinAngle",
- initialValue: 0.0,
- setPrimitiveFunction: getBoundSetter("minClippingBounds", "z"),
- getPrimitiveFunction: function () {
- that.clippingCylinderMinAngle = that._voxelPrimitive.minClippingBounds.z;
- },
- });
- addProperty({
- name: "translationX",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.translationX = Matrix4.getTranslation(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).x;
- },
- });
- addProperty({
- name: "translationY",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.translationY = Matrix4.getTranslation(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).y;
- },
- });
- addProperty({
- name: "translationZ",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.translationZ = Matrix4.getTranslation(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).z;
- },
- });
- addProperty({
- name: "scaleX",
- initialValue: 1.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.scaleX = Matrix4.getScale(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).x;
- },
- });
- addProperty({
- name: "scaleY",
- initialValue: 1.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.scaleY = Matrix4.getScale(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).y;
- },
- });
- addProperty({
- name: "scaleZ",
- initialValue: 1.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- getPrimitiveFunction: function () {
- that.scaleZ = Matrix4.getScale(
- that._voxelPrimitive.modelMatrix,
- new Cartesian3()
- ).z;
- },
- });
- addProperty({
- name: "angleX",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- });
- addProperty({
- name: "angleY",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- });
- addProperty({
- name: "angleZ",
- initialValue: 0.0,
- setPrimitiveFunction: function () {
- if (that._modelMatrixReady) {
- setModelMatrix(that);
- }
- },
- });
- }
- const scratchTranslation = new Cartesian3();
- const scratchScale = new Cartesian3();
- const scratchHeadingPitchRoll = new HeadingPitchRoll();
- const scratchRotation = new Matrix3();
- function setModelMatrix(viewModel) {
- const translation = Cartesian3.fromElements(
- viewModel.translationX,
- viewModel.translationY,
- viewModel.translationZ,
- scratchTranslation
- );
- const scale = Cartesian3.fromElements(
- viewModel.scaleX,
- viewModel.scaleY,
- viewModel.scaleZ,
- scratchScale
- );
- const hpr = scratchHeadingPitchRoll;
- hpr.heading = viewModel.angleX;
- hpr.pitch = viewModel.angleY;
- hpr.roll = viewModel.angleZ;
- const rotation = Matrix3.fromHeadingPitchRoll(hpr, scratchRotation);
- const rotationScale = Matrix3.multiplyByScale(rotation, scale, rotation);
- viewModel._voxelPrimitive.modelMatrix = Matrix4.fromRotationTranslation(
- rotationScale,
- translation,
- viewModel._voxelPrimitive.modelMatrix
- );
- }
- Object.defineProperties(VoxelInspectorViewModel.prototype, {
- /**
- * Gets the scene
- * @memberof VoxelInspectorViewModel.prototype
- * @type {Scene}
- * @readonly
- */
- scene: {
- get: function () {
- return this._scene;
- },
- },
- /**
- * Gets or sets the primitive of the view model.
- * @memberof VoxelInspectorViewModel.prototype
- * @type {VoxelPrimitive}
- */
- voxelPrimitive: {
- get: function () {
- return this._voxelPrimitive;
- },
- set: function (voxelPrimitive) {
- if (defined(this._customShaderCompilationRemoveCallback)) {
- this._customShaderCompilationRemoveCallback();
- }
- // Update properties from the new primitive
- if (defined(voxelPrimitive)) {
- this._voxelPrimitive = voxelPrimitive;
- const that = this;
- // This is here for backwards compatibility. This can be done immediately once readyPromise is removed.
- that._voxelPrimitive._readyPromise.then(function () {
- that._customShaderCompilationRemoveCallback = that._voxelPrimitive.customShaderCompilationEvent.addEventListener(
- function (error) {
- const shaderString =
- that._voxelPrimitive.customShader.fragmentShaderText;
- that.shaderString = formatShaderString(shaderString);
- if (!defined(error)) {
- that.shaderCompilationMessage = "Shader compiled successfully!";
- that.shaderCompilationSuccess = true;
- } else {
- that.shaderCompilationMessage = error.message;
- that.shaderCompilationSuccess = false;
- }
- }
- );
- that._modelMatrixReady = false;
- for (let i = 0; i < that._getPrimitiveFunctions.length; i++) {
- that._getPrimitiveFunctions[i]();
- }
- that._modelMatrixReady = true;
- setModelMatrix(that);
- });
- }
- },
- },
- });
- /**
- * Toggles the inspector visibility
- */
- VoxelInspectorViewModel.prototype.toggleInspector = function () {
- this.inspectorVisible = !this.inspectorVisible;
- };
- /**
- * Toggles the visibility of the display section
- */
- VoxelInspectorViewModel.prototype.toggleDisplay = function () {
- this.displayVisible = !this.displayVisible;
- };
- /**
- * Toggles the visibility of the transform section
- */
- VoxelInspectorViewModel.prototype.toggleTransform = function () {
- this.transformVisible = !this.transformVisible;
- };
- /**
- * Toggles the visibility of the bounds section
- */
- VoxelInspectorViewModel.prototype.toggleBounds = function () {
- this.boundsVisible = !this.boundsVisible;
- };
- /**
- * Toggles the visibility of the clipping section
- */
- VoxelInspectorViewModel.prototype.toggleClipping = function () {
- this.clippingVisible = !this.clippingVisible;
- };
- /**
- * Toggles the visibility of the shader section
- */
- VoxelInspectorViewModel.prototype.toggleShader = function () {
- this.shaderVisible = !this.shaderVisible;
- };
- /**
- * Compiles the shader in the shader editor.
- */
- VoxelInspectorViewModel.prototype.compileShader = function () {
- if (defined(this._voxelPrimitive)) {
- // It's assumed that the same uniforms are going to be used regardless of edits.
- this._voxelPrimitive.customShader = new CustomShader({
- fragmentShaderText: this.shaderString,
- uniforms: this._voxelPrimitive.customShader.uniforms,
- });
- }
- };
- /**
- * Handles key press events on the shader editor.
- */
- VoxelInspectorViewModel.prototype.shaderEditorKeyPress = function (
- sender,
- event
- ) {
- if (event.keyCode === 9) {
- //tab
- event.preventDefault();
- const textArea = event.target;
- const start = textArea.selectionStart;
- const end = textArea.selectionEnd;
- let newEnd = end;
- const selected = textArea.value.slice(start, end);
- const lines = selected.split("\n");
- const length = lines.length;
- let i;
- if (!event.shiftKey) {
- for (i = 0; i < length; ++i) {
- lines[i] = ` ${lines[i]}`;
- newEnd += 2;
- }
- } else {
- for (i = 0; i < length; ++i) {
- if (lines[i][0] === " ") {
- if (lines[i][1] === " ") {
- lines[i] = lines[i].substr(2);
- newEnd -= 2;
- } else {
- lines[i] = lines[i].substr(1);
- newEnd -= 1;
- }
- }
- }
- }
- const newText = lines.join("\n");
- textArea.value =
- textArea.value.slice(0, start) + newText + textArea.value.slice(end);
- textArea.selectionStart = start !== end ? start : newEnd;
- textArea.selectionEnd = newEnd;
- } else if (event.ctrlKey && (event.keyCode === 10 || event.keyCode === 13)) {
- //ctrl + enter
- this.compileShader();
- }
- return true;
- };
- /**
- * @returns {boolean} true if the object has been destroyed, false otherwise.
- */
- VoxelInspectorViewModel.prototype.isDestroyed = function () {
- return false;
- };
- /**
- * Destroys the widget. Should be called if permanently
- * removing the widget from layout.
- */
- VoxelInspectorViewModel.prototype.destroy = function () {
- const that = this;
- this._definedProperties.forEach(function (property) {
- knockout.getObservable(that, property).dispose();
- });
- return destroyObject(this);
- };
- export default VoxelInspectorViewModel;
|