Java code for changing material color in Cult3D

Source: Internet
Author: User

Java code for changing material color in Cult3D

Example: 
Define a new color Color, such as "private Color red = new color (198, 58, 41);" add the variable name to the colors array, use the changeColor method to change the color cyclically.

  Modify the following settings: 
Import com. cult3d. *; import com. cult3d. world. *; import java. awt. color; import java. awt. image; import java. awt. graphics; public class ColorSwap implements Cult3DScript, Runnable {// The value of TEXTURE_NAME is the name of the texture you want to change. private static final String TEXTURE_NAME = "MADAROSE "; // if you want to add more colors add a Color instance here // and add it to the colors array. the numbers are in RGB values (0 to 255, w Here 0 is black and 255 is white) private Color red = new Color (198, 58, 41); private Color blue = new Color (99, 93,163 ); private Color green = new Color (138,149, 78); private Color gray = new Color (136,136,136); private Color lightBlue = new Color (121,130,173 ); private Color black = new Color (64, 64, 64); private Color [] colors = {red, blue, green, gray, lightBlue, black }; //////////////// //////////////////////////////////////// //////////////// Private Texture texture; private TextureImage textureImage; private int textureWidth, textureHeight; private Graphics graphics; // declare this variable volatile, so it always keeps the right value private volatile boolean loaded = false; private int colorCounter = 0; // Standard constructor public ColorSwap () {Thread thread = new Thread (This); thread. start ();} // Thread method which loads "heavy" resources/textures // To avoid the viewer hang when loading. public void run () {texture = new Texture (TEXTURE_NAME); textureWidth = texture. getWidth (); textureHeight = texture. getHeight (); textureImage = (TextureImage) Cult. createImage (textureWidth, textureHeight); graphics = textureImage. getGraphics (); loaded = true;}/* Note: Lines Started with two slashes (//) is line comments and is not in the final class file, lines with slash-star is another comment which is called "block comment" which comments a block of code until it encounters star-slash. as * // use this method from the Designer to loop the colors. public void changeColor (String s) {if (! Loaded) {System. out. println ("The Java code is not yet loaded"); return;} if (colorCounter> = colors. length) {colorCounter = 0;} switchColor (colors [colorCounter]); colorCounter ++;} // The actual color change private void switchColor (Color color) {graphics. setColor (color); graphics. fillRect (0, 0, textureWidth, textureHeight); texture. setTexture (textureImage);} public void cult3dDestroy (){}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.