# Laden von Texturen nicht möglich



## maxf (31. Okt 2005)

Hallo,

ich habe folgendes problem: Wenn ich in Eclipse(V3.1) versuche eine Textuer zu laden,
erhalte ich folgende Fehlermeldung: *The method setTexture(Texture)
in the type Appearance is not applicable for the arguments (Texture)*
Code:
	
	
	
	





```
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.Image;

import javax.media.j3d.*;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
//import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.Component;


public class Game extends Applet{
	
	private SimpleUniverse u = null;
	
	public BranchGroup createSceneGraph() {
		BranchGroup RootBG=new BranchGroup();
		TransformGroup SphereTG=new TransformGroup();
		Transform3D SphereT3D=new Transform3D();
		Appearance SphereAppearance=new Appearance();
		AmbientLight ALgt=new AmbientLight(new Color3f(1f,1f,1f));
		DirectionalLight DLgt=new DirectionalLight(new Color3f(1f,1f,1f),new Vector3f(-0.5f,-0.5f,-1f));
		BoundingSphere BigBounds=new BoundingSphere(new Point3d(),100000);
		ALgt.setInfluencingBounds(BigBounds);
		DLgt.setInfluencingBounds(BigBounds);
		SphereT3D.setTranslation(new Vector3f(0f,0f,-1.5f));
		SphereTG.setTransform(SphereT3D);
		SphereAppearance.setMaterial(new Material(new Color3f(0f,0f,1f),new Color3f(0f,0f,0f),new Color3f(1f,0f,0f),new Color3f(1f,1f,1f),100f));
		//Texture text = TextureLoader.INSTANCE.getTexture("texturen/Wand.jpg");
		SphereAppearance.setTexture(TextureLoader.INSTANCE.getTexture("texturen/Wand.jpg"));
		SphereAppearance.setTexCoordGeneration(new TexCoordGeneration(TexCoordGeneration.SPHERE_MAP,TexCoordGeneration.TEXTURE_COORDINATE_2));
		SphereAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE,new Transform3D(),new Color4f(),TextureAttributes.NICEST));
		SphereTG.addChild(new Sphere(1.0f,Sphere.GENERATE_NORMALS,40,SphereAppearance));
		RootBG.addChild(SphereTG);
		RootBG.addChild(ALgt);
		RootBG.addChild(DLgt);
		RootBG.compile();
		return RootBG;
	}

	public Game(){
	}

	public void init(){
		setLayout(new BorderLayout());
		GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
		Canvas3D c = new Canvas3D(config);
		add("Center", c);
		u = new SimpleUniverse(c);
		u.getViewingPlatform().setNominalViewingTransform();
		u.addBranchGraph(createSceneGraph());
	}

	public void destroy(){
		u.cleanup();
	}

	public static void main(String[] args) {
		new MainFrame(new Game(), 400, 400);
	}
}
```
Bitte helft mir!


----------



## MPW (31. Okt 2005)

Irgendwie ist deine TexttureLoader.INSTANCE.getTexture-Konstruktion auch etwas merkwürdig, ich hab' mal das hier gefunden, kannst's ja mal ausprobieren:


```
earthAppear.setTexture( new TextureLoader(TEXTURE_FNAME, this).getTexture());
```


----------



## maxf (31. Okt 2005)

MPW hat gesagt.:
			
		

> Irgendwie ist deine TexttureLoader.INSTANCE.getTexture-Konstruktion auch etwas merkwürdig, ich hab' mal das hier gefunden, kannst's ja mal ausprobieren:
> 
> 
> ```
> ...



Finktioniert auch nicht, Fehlermeldung:
*The constructor TextureLoader(String, Game) is undefined.*

Ich habs nochmal anders probiert, funktioniert auch nicht:

```
SphereAppearance.setTexture( new TextureLoader("texturen/Wand.jpg", new Component()).getTexture());
```
Fehlermeldung:
*The constructor TextureLoader(String, Component) is undefined.*


----------



## MPW (31. Okt 2005)

Versuch mal null, statt this oder new Component()


----------



## maxf (1. Nov 2005)

Funktioniert leider auch nicht. :cry:


----------



## MPW (1. Nov 2005)

hgr....das gibt's doch garnicht.

Welche Versionen hast du überhaupt, kann es sein, dass das nur an Eclipse liegt, oder kommen die Fehler schon direkt vom Kompiler?

Hier, kompilier mal den Code, dann sehen wir weiter:


```
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.picking.*;
import com.sun.j3d.utils.picking.PickResult;

class MPWJumper extends Frame implements Runnable {
	private SimpleUniverse uni = null;
	BranchGroup RootBG;
	private TransformGroup transformGroup;
	private Transform3D trans = new Transform3D(),tempTrans=new Transform3D();
	private WakeupCriterion criterion;
	static int speed = 0;
	Thread move;
	static int seit = 0;
	static int up = 0;
	static int down = 0;
	Point3d pos = new Point3d();


	public MPWJumper() {
		setLayout(new BorderLayout());
		setSize(640, 480);
		setTitle("MPW-Jumper Version 0.1 written by Matthias Walther");
		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
		Canvas3D c = new Canvas3D(config);
		add("Center", c);
		uni = new SimpleUniverse(c);
		addWindowListener( new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				setVisible(false);
				dispose();
				System.exit(0);
			}
		});
		setVisible(true);
		setViewPosition();
		uni.addBranchGraph(createSceneGraph());
		transformGroup=uni.getViewingPlatform().getViewPlatformTransform();
		move = new Thread(this);
		move.start();
	}
	void setViewPosition() {
		TransformGroup ViewTG;
		Transform3D ViewT3D = new Transform3D();
		ViewTG = uni.getViewingPlatform().getViewPlatformTransform();
		ViewTG.getTransform(ViewT3D);
		ViewT3D.setTranslation(new Vector3f(0f, 0.3f, 0f));
		ViewTG.setTransform(ViewT3D);
	}
	void createStarBackground(BranchGroup bg) {
		java.util.Random rand = new java.util.Random();
		float mag;
		BranchGroup BGBranch = new BranchGroup();
		Background BG = new Background();

		PointArray starfield = new PointArray(15000, PointArray.COORDINATES|PointArray.COLOR_3);
		float[] point = new float[3];
		float[] brightness = new float[3];
		for (int i = 0; i<15000; i++) {
			point[0] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f : rand.nextFloat();
			point[1] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f : rand.nextFloat();
			point[2] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f : rand.nextFloat();
			starfield.setCoordinate(i, point);
			mag = (rand.nextFloat() +0.5f) /1.5f;
			brightness[0] = mag;
			brightness[1] = mag;
			brightness[2] = mag;
			starfield.setColor(i, brightness);
		}
		Shape3D StarShape = new Shape3D(starfield);
		StarShape.setAppearance(new Appearance());
		StarShape.getAppearance().setPointAttributes(new PointAttributes(1f, true));
		BGBranch.addChild(StarShape);
		BG.setGeometry(BGBranch);
		BG.setApplicationBounds(new BoundingSphere(new Point3d(), 10000000.0));
		bg.addChild(BG);
	}


	public BranchGroup createSceneGraph() {
		RootBG=new BranchGroup();
		BoundingSphere BigBounds = new BoundingSphere(new Point3d(0f, 0f, 0f), 1000000f);
		Appearance BoxAppearance = new Appearance();
		AmbientLight ALgt = new AmbientLight(new Color3f(1f, 1f, 1f));
		ALgt.setInfluencingBounds(BigBounds);

		TransformGroup box[] = new TransformGroup[100];
		Transform3D box3D[] = new Transform3D[100];

		BoxAppearance.setTexture((new TextureLoader("Texturen/test.jpg", null)).getTexture());
		BoxAppearance.setTexCoordGeneration(new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_3));
		BoxAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(), TextureAttributes.NICEST));
		BoxAppearance.setMaterial(new Material(new Color3f(0.1f, 0.1f, 0.1f), new Color3f(0f, 0f, 0f), new Color3f(0.8f, 0.8f, 0.8f), new Color3f(0.6f, 0.6f, 0.6f), 1f));
		BoxAppearance.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
		float x, y, z;
		x = 0f;
		y = 0f;
		z = -5f;
		for (int i = 0; i < box.length; i++) {
			box[i] = new TransformGroup();
			box3D[i] = new Transform3D();
			box3D[i].setTranslation(new Vector3f(x, y, z));
			z = z-10f;
			y = y+(float)0.2;
			box[i].setTransform(box3D[i]);
			box[i].addChild(new Box(1.0f, 0.1f, 5.0f, BoxAppearance));
			RootBG.addChild(box[i]);
		}


		KeyBehavior KeyCtrl = new KeyBehavior(uni.getViewingPlatform().getViewPlatformTransform());
		KeyCtrl.setSchedulingBounds(BigBounds);
		RootBG.addChild(KeyCtrl);
		RootBG.addChild(ALgt);
		createStarBackground(RootBG);
		setTerrainFollowEnable(true, RootBG, 0.3);

  		RootBG.compile();
		return RootBG;
	}

	public static void main(String args[]) {
		new MPWJumper();
	}
	public void run() {
	  	transformGroup.getTransform(trans);
	   	tempTrans.setIdentity();
		while (true) {
			if (speed > 0) {
				tempTrans.setTranslation(new Vector3f(0f,0f,(-0.1f*speed/100)));
			}
			trans.mul(tempTrans);
	  	    transformGroup.setTransform(trans);
			if (seit != 0) {
				if (seit > 0) {
					tempTrans.setTranslation(new Vector3f(0.004f*seit/25,0f,0f));
					seit--;
				}
				if (seit < 0) {
					tempTrans.setTranslation(new Vector3f(-0.004f*seit/(-25),0f,0f));
					seit++;
				}
				trans.mul(tempTrans);
	  		    	transformGroup.setTransform(trans);
			} else {
				tempTrans.setTranslation(new Vector3f(0f, 0f, 0f));
				trans.mul(tempTrans);
	  		    transformGroup.setTransform(trans);
			}
			if (up > 0) {
				tempTrans.setTranslation(new Vector3f(0f,(float)0.00005f*(up*up/7),0f));
				up--;
				trans.mul(tempTrans);
	  		    transformGroup.setTransform(trans);
	  		    down = 0;
			} else {
				//if (
				int x = down*down/10;
				tempTrans.setTranslation(new Vector3f(0f,x/-1000,0f));
				trans.mul(tempTrans);
	    		transformGroup.setTransform(trans);
				down++;
			}
			Transform3D myTransform = new Transform3D();
			uni.getViewingPlatform().getViewPlatformTransform().getTransform(myTransform);
			Vector3f position = new Vector3f();
			myTransform.get(position);

			PickRay ser = new PickRay(new Point3d(position), new Vector3d(0f, -1f, 0f));
			PickResult one = null;
			if (RootBG.pickClosest(ser) != null) {
				one = new PickResult(RootBG.pickClosest(ser), new PickRay(new Point3d(position), new Vector3d(0f, -1f, 0f)));
			}
			int yes = one.getDistance();


			if (RootBG.pickClosest(ser) != null) {
				System.out.println(RootBG.pickClosest(ser));
			} else {
				System.out.println("nix gefunden");
			}
			try {
				move.sleep(10);
			} catch (InterruptedException e) {
			}
		}
	}
}
```



```
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.picking.PickTool;
import javax.vecmath.*;
import java.util.*;

public class KeyBehavior extends Behavior{
	private TransformGroup transformGroup;
	private Transform3D trans = new Transform3D(),tempTrans=new Transform3D();
	private WakeupCriterion criterion;

	public KeyBehavior(TransformGroup tg) {
		transformGroup=tg;
	}

	public void initialize() {
		criterion=new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
		wakeupOn(criterion);
	}

	public void processStimulus(Enumeration criteria) {
		WakeupOnAWTEvent ev;
		AWTEvent AWTEv[];
		KeyEvent KeyEv;
		while (criteria.hasMoreElements()) {
    		ev = (WakeupOnAWTEvent)criteria.nextElement();
    		AWTEv = ev.getAWTEvent();
        	for (int i=0; i<AWTEv.length; i++) {
        	    KeyEv=(KeyEvent)AWTEv[i];
        	    if (KeyEv.getKeyCode()==KeyEvent.VK_UP) {
					MPWJumper.speed++;
				} else if (KeyEv.getKeyCode()==KeyEvent.VK_DOWN) {
					if (MPWJumper.speed > 0) {
						if (MPWJumper.speed > 4) {
							MPWJumper.speed = MPWJumper.speed-5;
						} else {
							MPWJumper.speed--;
						}
					}
				} else if (KeyEv.getKeyCode()==KeyEvent.VK_LEFT) {
					MPWJumper.seit = -50;
        	    } else if (KeyEv.getKeyCode()==KeyEvent.VK_RIGHT) {
					MPWJumper.seit = +50;
				} else if (KeyEv.getKeyCode()==KeyEvent.VK_SPACE) {
					if (MPWJumper.up < 10) {
						MPWJumper.up = +50;
					}
				}
        	}
        }
        wakeupOn(criterion);
    }
}
```

Das ist zwar nicht so sauber programmiert, hab' aber gerade nix besseres, in den Ordner Texturen packst du dann noch eine Datei mit dem Namen "test.jpg"/Inhalt ist ja egal/ und dann schau erstmal ob das geht....


----------



## maxf (1. Nov 2005)

Ich verwende Win2k Server, Eclipse 3.1.1, JRE/JDK 1.5_5, Java 3D API 1.3.1

P.S.: Es läuft immer noch nicht.


----------



## MPW (1. Nov 2005)

Auch mein Code nicht?
Obwohl eine Texturedatei da ist,

was gibt's denn als Exception,
kompilieren lässt sich der Code ja, da ich ihn getestet hab!


----------



## maxf (3. Nov 2005)

Ich habe rausgefunden, warums nicht läuft:
Es waren Zwei gleichnemige Klassen im classpath.
Diese waren aber für JGOL(oder wie auch immer).
Trozdem vielen Dank!


----------



## MPW (6. Nov 2005)

Was ist denn das für eine Entwicklungsumgebung, wenn die das nicht merkt, weil der Compiler merkt ja sowas an, die IDE muss sowas eigentlich weitergeben....


----------



## Guest (7. Nov 2005)

Eclipse 3.1.1


----------



## maxf (7. Nov 2005)

Hoppla, vergessen einzuloggen.
Neues Problem: hier


----------

