mtr_addon:nte:js:resources
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
mtr_addon:nte:js:resources [2024/02/06 13:04] – ↷ Страница перемещена и переименована из mtr_addon:nte:objtrains в mtr_addon:nte:js:resources weryskok | mtr_addon:nte:js:resources [2024/02/08 05:35] (current) – Minor fixes lx862 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Resource Loading ====== | ||
+ | |||
+ | NTE provides several methods for controlling the loading and retrieval of resources within resource packs in JavaScript scripts. | ||
+ | |||
+ | Code written in the top-level space outside of functions will be executed when a resource pack is loaded and can be used to initialize resources such as models, textures, etc. Resources that should not be different for each train (such as models and such) are recommended to be stored in global variables to avoid excessive memory usage when loading a copy of the same content for each train. | ||
+ | |||
+ | ===== ResourceLocation ===== | ||
+ | |||
+ | Minecraft uses a '' | ||
+ | |||
+ | * <code javascript> | ||
+ | static Resources.id(idStr: | ||
+ | </ | ||
+ | * Converts the string to the appropriate '' | ||
+ | * <code javascript> | ||
+ | static Resources.idr(relPath: | ||
+ | </ | ||
+ | * Converts the string to '' | ||
+ | |||
+ | ===== Model Loading ===== | ||
+ | |||
+ | The way to handle the model in NTE is that the model file should first be loaded as '' | ||
+ | |||
+ | * <code javascript> | ||
+ | static ModelManager.loadRawModel(Resources.manager(), | ||
+ | </ | ||
+ | * Loads a model as a whole as a '' | ||
+ | * <code javascript> | ||
+ | static ModelManager.loadPartedRawModel(Resources.manager(), | ||
+ | </ | ||
+ | * Loads each group of a model into individual RawModels, returning a Java Map. | ||
+ | * <code javascript> | ||
+ | static ModelManager.uploadVertArrays(rawModel: | ||
+ | </ | ||
+ | * Uploads the RawModel to the GPU's video memory (VRAM), returning the uploaded '' | ||
+ | |||
+ | ===== Loading AWT Resources ===== | ||
+ | |||
+ | These functions load the resources used to draw dynamic textures via the Java AWT. | ||
+ | |||
+ | * <code javascript> | ||
+ | static Resources.getSystemFont(name: | ||
+ | </ | ||
+ | * Get a system or MTR built-in font. | ||
+ | |||
+ | ^ Font Name ^ Description ^ | ||
+ | | Noto Serif | MTR's built-in serif font (similar to Song). Identical on all systems. | | ||
+ | | Noto Sans | NTE Built-in sans serif font (similar to Helvetica). Identical on all systems. | | ||
+ | | Serif | A serif font selected by AWT that is installed on this computer. May be different on different devices. | | ||
+ | | SansSerif | A sans serif font selected by AWT that is installed on this computer. May be different on different devices. | | ||
+ | | Monospaced | A monospaced font selected by AWT that is installed on this computer. May be different on different devices. | | ||
+ | |||
+ | * <code javascript> | ||
+ | static Resources.readBufferedImage(path: | ||
+ | </ | ||
+ | * Loads an image file as an AWT BufferedImage. | ||
+ | * <code javascript> | ||
+ | static Resources.readFont(path: | ||
+ | </ | ||
+ | * Load a custom TTF or OTF font file as an AWT Font. | ||
+ | * //Note: Due to the way Java and Minecraft Resource Pack works, new temporary font files are generated on your disk every time you call this function. If you find yourself running out of disk space during the development, | ||
+ | * <code javascript> | ||
+ | static Resources.getFontRenderContext(): | ||
+ | </ | ||
+ | * Get an AWT FontRenderContext. | ||
+ | |||
+ | ===== Reading resource files ===== | ||
+ | |||
+ | * <code javascript> | ||
+ | static Resources.readString(location: | ||
+ | </ | ||
+ | * Reads the contents of a resource file as a string. Returns null if reading fails. | ||
+ | |||
+ | ===== Misc ===== | ||
+ | |||
+ | * <code javascript> | ||
+ | static Resources.parseNbtString(nbtStr: | ||
+ | </ | ||
+ | * Returns Minecraft' | ||
+ | |||
+ | ===== RawModel ===== | ||
+ | |||
+ | ^ Functions ^ Description ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | If the same model needs to be modified in different ways, it may be necessary to copy the model. For example, '' | ||
+ | |||
+ | If you don't need to change the geometry, but only need to change the material or replace the texture, you can use '' | ||
+ | |||
+ | ===== ModelCluster ===== | ||
+ | |||
+ | Once the model is uploaded to the GPU video memory, the vertices can no longer be changed, however the texture may still be changed. Therefore, if you need to replace textures several times, you can upload the model as a ModelCluster first and then replace the textures, thus avoiding the unnecessary uploading of the model (Where you upload each model with a different textures each time). | ||
+ | |||
+ | ^ Functions ^ Description ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | ===== Source ===== | ||
+ | |||
+ | * [[https:// | ||
+ | |||
mtr_addon/nte/js/resources.1707224687.txt.gz · Last modified: 2024/02/06 13:04 by weryskok