Java Code Examples for com.sun.j3d.utils.image.TextureLoader

The following examples show how to use com.sun.j3d.utils.image.TextureLoader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: javagame   Source File: Ball.java    License: MIT License 5 votes vote down vote up
/**
 * �e�N�X�`�������[�h
 * 
 * @param filename �t�@�C����
 * @return �e�N�X�`��
 */
private Texture loadTexture(String filename) {
    Texture texture;

    texture = new TextureLoader(getClass().getResource(filename), null)
            .getTexture();

    return texture;
}
 
Example 2
Source Project: javagame   Source File: Ball.java    License: MIT License 5 votes vote down vote up
/**
 * �e�N�X�`�������[�h
 * 
 * @param filename �t�@�C����
 * @return �e�N�X�`��
 */
private Texture loadTexture(String filename) {
    Texture texture;

    texture = new TextureLoader(getClass().getResource(filename), null)
            .getTexture();

    return texture;
}
 
Example 3
Source Project: javagame   Source File: Main.java    License: MIT License 5 votes vote down vote up
/**
 * �e�N�X�`�������[�h
 * 
 * @param filename �t�@�C����
 * @return �e�N�X�`��
 */
private Texture loadTexture(String filename) {
    Texture texture;

    texture = new TextureLoader(getClass().getResource(filename), null)
            .getTexture();

    return texture;
}
 
Example 4
Source Project: javagame   Source File: CrystalBall.java    License: MIT License 5 votes vote down vote up
/**
 * �e�N�X�`�������[�h
 * @param filename �t�@�C����
 * @return �e�N�X�`��
 */
private Texture loadTexture(String filename) {
    Texture texture;
    
    texture = new TextureLoader(getClass().getResource(filename), null).getTexture();

    return texture;
}
 
Example 5
Source Project: GpsPrune   Source File: Java3DWindow.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a java3d Shape for the terrain
 * @param inModel threedModel
 * @param inHelper terrain helper
 * @param inBaseImage base image for shape, or null for no image
 * @return Shape3D object
 */
private static Shape3D createTerrain(ThreeDModel inModel, TerrainHelper inHelper, GroutedImage inBaseImage)
{
	final int numNodes = inHelper.getGridSize();
	final int RESULT_SIZE = numNodes * (numNodes * 2 - 2);
	int[] stripData = inHelper.getStripLengths();

	// Get the scaled terrainTrack coordinates (or just heights) from the model
	final int nSquared = numNodes * numNodes;
	Point3d[] rawPoints = new Point3d[nSquared];
	for (int i=0; i<nSquared; i++)
	{
		double height = inModel.getScaledTerrainValue(i) * MODEL_SCALE_FACTOR;
		rawPoints[i] = new Point3d(inModel.getScaledTerrainHorizValue(i) * MODEL_SCALE_FACTOR,
			Math.max(height, 0.05), // make sure it's above the box
			-inModel.getScaledTerrainVertValue(i) * MODEL_SCALE_FACTOR);
	}

	GeometryInfo gi = new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
	gi.setCoordinates(inHelper.getTerrainCoordinates(rawPoints));
	gi.setStripCounts(stripData);

	Appearance tAppearance = new Appearance();
	if (inBaseImage != null)
	{
		gi.setTextureCoordinateParams(1, 2); // one coord set of two dimensions
		gi.setTextureCoordinates(0, inHelper.getTextureCoordinates());
		Texture mapImage = new TextureLoader(inBaseImage.getImage()).getTexture();
		tAppearance.setTexture(mapImage);
		TextureAttributes texAttr = new TextureAttributes();
		texAttr.setTextureMode(TextureAttributes.MODULATE);
		tAppearance.setTextureAttributes(texAttr);
	}
	else
	{
		Color3f[] colours = new Color3f[RESULT_SIZE];
		Color3f terrainColour = new Color3f(0.1f, 0.2f, 0.2f);
		for (int i=0; i<RESULT_SIZE; i++) {colours[i] = terrainColour;}
		gi.setColors(colours);
	}
	new NormalGenerator().generateNormals(gi);
	Material terrnMat = new Material(new Color3f(0.4f, 0.4f, 0.4f), // ambient colour
		new Color3f(0f, 0f, 0f), // emissive (none)
		new Color3f(0.8f, 0.8f, 0.8f), // diffuse
		new Color3f(0.2f, 0.2f, 0.2f), //specular
		30f); // shinyness
	tAppearance.setMaterial(terrnMat);
	return new Shape3D(gi.getGeometryArray(), tAppearance);
}
 
Example 6
Source Project: jMAVSim   Source File: Visualizer3D.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void createEnvironment() {
    BranchGroup group = new BranchGroup();
    // Sky
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
    Background bg = new Background();
    bg.setApplicationBounds(bounds);
    BranchGroup backGeoBranch = new BranchGroup();
    Sphere skySphere = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 32);
    //        Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 32);
    Texture texSky = new TextureLoader("environment/sky.jpg", null).getTexture();
    skySphere.getAppearance().setTexture(texSky);
    Transform3D transformSky = new Transform3D();
    //transformSky.setTranslation(new Vector3d(0.0, 0.0, -0.5));
    Matrix3d rot = new Matrix3d();
    rot.rotX(Math.PI / 2);
    transformSky.setRotation(rot);
    TransformGroup tgSky = new TransformGroup(transformSky);
    tgSky.addChild(skySphere);
    backGeoBranch.addChild(tgSky);
    bg.setGeometry(backGeoBranch);
    group.addChild(bg);
    //group.addChild(tgSky);
    // Ground
    QuadArray polygon1 = new QuadArray(4, QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
    polygon1.setCoordinate(0, new Point3f(-1000f, 1000f, 0f));
    polygon1.setCoordinate(1, new Point3f(1000f, 1000f, 0f));
    polygon1.setCoordinate(2, new Point3f(1000f, -1000f, 0f));
    polygon1.setCoordinate(3, new Point3f(-1000f, -1000f, 0f));
    polygon1.setTextureCoordinate(0, 0, new TexCoord2f(0.0f, 0.0f));
    polygon1.setTextureCoordinate(0, 1, new TexCoord2f(10.0f, 0.0f));
    polygon1.setTextureCoordinate(0, 2, new TexCoord2f(10.0f, 10.0f));
    polygon1.setTextureCoordinate(0, 3, new TexCoord2f(0.0f, 10.0f));
    Texture texGround = new TextureLoader("environment/grass2.jpg", null).getTexture();
    Appearance apGround = new Appearance();
    apGround.setTexture(texGround);
    Shape3D ground = new Shape3D(polygon1, apGround);
    Transform3D transformGround = new Transform3D();
    transformGround.setTranslation(
            new Vector3d(0.0, 0.0, 0.005 + world.getEnvironment().getGroundLevel(new Vector3d(0.0, 0.0, 0.0))));
    TransformGroup tgGround = new TransformGroup(transformGround);
    tgGround.addChild(ground);
    group.addChild(tgGround);

    // Light
    DirectionalLight light1 = new DirectionalLight(white, new Vector3f(4.0f, 7.0f, 12.0f));
    light1.setInfluencingBounds(sceneBounds);
    group.addChild(light1);
    AmbientLight light2 = new AmbientLight(new Color3f(0.5f, 0.5f, 0.5f));
    light2.setInfluencingBounds(sceneBounds);
    group.addChild(light2);

    // Update behavior
    Behavior b = new UpdateBehavior();
    b.setSchedulingBounds(bounds);
    group.addChild(b);
    universe.addBranchGraph(group);
}