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.
new GraphicsTexture(width: int, height: int)
create
function and placed in state
.GraphicsTexture.close(): void
create
train function, it must be deleted in the dispose
function, otherwise it will continue to occupy memory, thus creating a memory leak.GraphicsTexture.bufferedImage: BufferedImage
GraphicsTexture.graphics: Graphics2D
GraphicsTexture.upload(): void
RateLimit
to reduce the frequency of texture updates. For example, the screen can be updated only 10 times per second, and it may not be updated at far distances, in some cases the information may not be updated at all.GraphicsTexture.identifier: ResourceLocation
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:
static Color.decode
, Color.WHITE…
, new Color
Graphics.setColor
, Graphics.setFont
, Graphics.setStroke(new BasicStroke(…))
Graphics.drawRect
, Graphics.fillRect
, Graphics.drawRoundRect
, Graphics.fillRoundRect
Graphics.drawImage
, Graphics.drawString
, Font.deriveFont
Graphics.setPaint(new GradientPaint(…))
, Graphics.fill(new Rectangle(…))
Graphics.getTransform
, Graphics.transform
, Graphics.setTransform
, AffineTransform.getTranslateInstance
, AffineTransform.getRotateInstance
Graphics.setClip
Graphics.getComposite
, Graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, …))
, Graphics.setComposite