⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 changecolour.java

📁 Java在Cult3D中的应用,运行环境:Win XP;JDK + 3DMAX.
💻 JAVA
字号:
import com.cult3d.*;
import com.cult3d.world.*;
import java.awt.Color;
import java.awt.Image;
import java.awt.Graphics;


public class  ChangeColour implements Cult3DScript, Runnable
{

	// change this name to the texture you have applied in your
	// modelling application.
	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, where 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 grey      = 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,
							  grey,
							  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 ChangeColour()
	{
		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;
	}

	

	
	public void red(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
                colorCounter = 0;
                switchColor(colors[colorCounter]);
        }
        
        public void Blue(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
               colorCounter = 1;
	       switchColor(colors[colorCounter]);
	}

        public void green(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
               colorCounter = 2;
	       switchColor(colors[colorCounter]);
	}

        public void grey(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
               colorCounter = 3;
	       switchColor(colors[colorCounter]);
	}
	
        public void lightBlue(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
               colorCounter =4;
	       switchColor(colors[colorCounter]);
	}

        public void black(String s)
	{
		if (!loaded)
		{
			System.out.println("The Java code is not yet loaded");
			return;
		}
               colorCounter = 5;
	       switchColor(colors[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()
	{
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -