Table of Contents

Dynamic Textures

NTE provides a GraphicsTexture class to use JS-controlled textures with dynamic content on models for LCD displays, blinking indicators, scrolling text LED, and so on.

GraphicsTexture

Example

importPackage(java.awt);
importPackage(java.awt.geom);
 
var rawTrainModel = ModelManager.loadRawModel(Resources.manager(), Resources.idr("train.obj"), null);
var baseTrainModel = ModelManager.uploadVertArrays(rawTrainModel);
 
function create(ctx, state, train) {
    state.pisTexture = new GraphicsTexture(1024, 256);
    state.trainModel = baseTrainModel.copyForMaterialChanges();
      state.trainModel.replaceTexture("pis_placeholder.png", state.pisTexture.identifier);
    state.pisRateLimit = new RateLimit(0.1);
}
 
function dispose(ctx, state, train) {
    state.pisTexture.close();
}
 
var serifFont = Resources.getSystemFont("Noto Serif");
 
function render(ctx, state, train) {
    if (state.pisRateLimit.shouldUpdate()) {
         let g = state.pisTexture.graphics;
        g.setColor(Color.WHITE);
        g.clearRect(0, 0, 1024, 256);
        g.setFont(serifFont.deriveFont(Font.BOLD, 32));
        g.setColor(Color.BLACK);
        g.drawString("Hello World!", 10, 40);
        state.pisTexture.upload();
    }
    for (i = 0; i < train.trainCars(); i++) {
        ctx.drawCarModel(state.trainModel, i, null);
    }
}

You can use the importPackage function from Rhino to satisfy the java.awt dependency when using AWT classes.

You can find some AWT tutorials on the Internet or look at the JavaDoc to see what drawing capabilities are available in Graphics2D:

The following functions can be used:

Source