rl-loadout-lib
Version:
Load Rocket League assets into three.js
93 lines • 4.5 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const rl_service_1 = require("../service/rl-service");
const decal_1 = require("../model/decal");
const factory_1 = require("../3d/body/factory");
const factory_2 = require("../3d/wheel/factory");
const mapping_1 = require("../loader/body/mapping");
const loader_1 = require("../utils/loader");
const decal_loader_1 = require("../loader/decal/decal-loader");
const mapping_2 = require("../loader/wheel/mapping");
/**
* Helper class to load items by their in game item ID.
*/
class RocketAssetManager {
constructor(config) {
this.config = config;
this.rlService = new rl_service_1.RocketLoadoutService(config.backendHost);
this.textureLoader = new loader_1.PromiseLoader(new loader_1.MultiImageLoader(config.textureFormat, config.loadingManager));
this.modelLoader = new loader_1.PromiseLoader(config.gltfLoader);
}
/**
* Completely load a car body model. This calls {@link BodyModel.load} on the body model, do **not** call it again.
* @param id in-game product id of the body
* @param paintConfig color configuration
* @param fallback if the body does not exist in the backend, fallback to this body, e.g.: {@link Body.DEFAULT}
* @param decalId in-game product id of the decal, no decal is applied if undefined
* @throws Error the body could not be found and there is no fallback
* @returns the loaded body model
*/
loadBody(id, paintConfig, fallback, decalId) {
return __awaiter(this, void 0, void 0, function* () {
let body;
let decal = decal_1.Decal.NONE;
if (decalId != undefined && decalId > 1) {
try {
decal = yield this.rlService.getDecal(decalId);
}
catch (e) {
}
}
try {
body = yield this.rlService.getBody(id);
}
catch (e) {
body = fallback;
}
if (body == undefined) {
throw new Error('body is undefined');
}
const loader = mapping_1.getBodyLoader(body.id);
const bodyAssetsTask = loader.load(body, this.modelLoader, this.textureLoader, this.config);
const decalAssetsTask = decal_loader_1.StaticDecalLoader.load(body, decal, this.textureLoader, this.config);
const bodyAssets = yield bodyAssetsTask;
const decalAssets = yield decalAssetsTask;
return factory_1.createBodyModel(body, decal, bodyAssets, decalAssets, paintConfig);
});
}
/**
* Completely load a car wheel model. This calls {@link WheelsModel.load} on the wheel model, do **not** call it again.
* @param id in-game product id of the wheels
* @param paintConfig color configuration
* @param fallback if the wheel does not exist in the backend, fallback to this wheel, e.g.: {@link Wheel.DEFAULT}
* @returns the loaded wheels model
*/
loadWheel(id, paintConfig, fallback) {
return __awaiter(this, void 0, void 0, function* () {
let wheel;
try {
wheel = yield this.rlService.getWheel(id);
}
catch (e) {
wheel = fallback;
}
if (wheel == undefined) {
throw new Error('wheel is undefined');
}
const loader = mapping_2.getWheelLoader(wheel.id);
const wheelAssets = yield loader.load(wheel, this.modelLoader, this.textureLoader, this.config);
return factory_2.createWheelsModel(wheel, wheelAssets, paintConfig);
});
}
}
exports.RocketAssetManager = RocketAssetManager;
//# sourceMappingURL=rocket-asset-manager.js.map