@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
101 lines (100 loc) • 6.59 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeometryInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const ModelGeometryDefinition_1 = __importDefault(require("../minecraft/ModelGeometryDefinition"));
var GeometryInfoGeneratorTest;
(function (GeometryInfoGeneratorTest) {
GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["blockGeometry"] = 101] = "blockGeometry";
GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["entityGeometry"] = 102] = "entityGeometry";
GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["itemGeometry"] = 103] = "itemGeometry";
GeometryInfoGeneratorTest[GeometryInfoGeneratorTest["overlyComplexBlockGeometry"] = 501] = "overlyComplexBlockGeometry";
})(GeometryInfoGeneratorTest || (exports.GeometryInfoGeneratorTest = GeometryInfoGeneratorTest = {}));
/**
* Validates and aggregates model geometry information from resource packs.
*
* @see {@link ../../public/data/forms/mctoolsval/geometry.form.json} for topic definitions
*/
class GeometryInfoGenerator {
id = "GEOMETRY";
title = "Model Geometry Validation";
summarize(info, infoSet) { }
async generate(project, contentIndex) {
const itemsCopy = project.getItemsCopy();
const blockGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.blockGeometry, "Block Geometry");
const entityGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.entityGeometry, "Entity Geometry");
const itemGeometryPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, GeometryInfoGeneratorTest.itemGeometry, "Items Geometry");
const items = [blockGeometryPi, entityGeometryPi, itemGeometryPi];
for (const projectItem of itemsCopy) {
if (projectItem.itemType === IProjectItemData_1.ProjectItemType.modelGeometryJson) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const srPath = projectItem.primaryFile.storageRelativePath.toLowerCase();
const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (modGeo && modGeo.definitions) {
for (const geoDef of modGeo.definitions) {
if (geoDef.bones) {
let totalCubes = 0;
for (const bone of geoDef.bones) {
if (bone.cubes) {
totalCubes += bone.cubes.length;
}
}
if (srPath.indexOf("/blocks/") >= 0) {
blockGeometryPi.spectrumIntFeature("Cubes", totalCubes);
const blockCubeBudget = 50;
if (totalCubes > blockCubeBudget) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, GeometryInfoGeneratorTest.overlyComplexBlockGeometry, `More than ${blockCubeBudget} cubes in custom blocks may lead to degraded performance. Cubes used`, projectItem, totalCubes));
}
}
else if (srPath.indexOf("/items/") >= 0 || srPath.indexOf("/attachable") >= 0) {
// note that sometimes this is in /entity, e.g., /entity/attachables, so this check needs to be first
itemGeometryPi.spectrumIntFeature("Cubes", totalCubes);
}
else if (srPath.indexOf("/entity/") >= 0) {
entityGeometryPi.spectrumIntFeature("Cubes", totalCubes);
}
}
if (geoDef.item_display_transforms) {
for (const itemDisplayKey in geoDef.item_display_transforms) {
const itemDisplayTransform = geoDef.item_display_transforms[itemDisplayKey];
if (!itemDisplayTransform) {
continue;
}
itemGeometryPi.incrementFeature(itemDisplayKey + " Item Display Transform");
if (itemDisplayTransform.fit_to_frame === true) {
itemGeometryPi.incrementFeature(itemDisplayKey + " Item Display Transform Fit To Frame True");
}
if (itemDisplayTransform.fit_to_frame === false) {
itemGeometryPi.incrementFeature(itemDisplayKey + " Item Display Transform Fit To Frame False");
}
if (itemDisplayTransform.scale) {
for (const scaleNum of itemDisplayTransform.scale) {
itemGeometryPi.spectrumFeature(itemDisplayKey + " Item Display Transform Scale ", scaleNum);
}
}
if (itemDisplayTransform.rotation) {
for (const rotationNum of itemDisplayTransform.rotation) {
itemGeometryPi.spectrumFeature(itemDisplayKey + " Item Display Transform Rotation ", rotationNum);
}
}
}
}
}
}
}
}
}
return items;
}
}
exports.default = GeometryInfoGenerator;