Good morning, Monkeys! (Or whatever time it is where you are). I’ve been having a problem with attaching a material to a cube… the tutorials work fine, but when I put in the URL for my own textures it gets messed up… From a distance, of course. Close up, it’s my texture. Pic: http://img580.imageshack.us/img580/6598/matprob4.png
http
http
http://img199.imageshack.us/img199/423/matprob3.png://img43.imageshack.us/img43/3113/matprob2.png://img217.imageshack.us/img217/7282/matprob1.png
Any ideas? Thanks!
-NomNom
More deteils please, what material are you useing ? how do you set it up?
Hi. Sorry, I ran out of time to post it and that was all I could get in I really was going to add more details later, but I just posted it in case anyone knew anything about it. Okay, so, details…
This is my code in general: [java]package main;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.bullet.BulletAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.GhostControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.effect.EmitterSphereShape;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.font.BitmapText;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.renderer.Camera;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Sphere.TextureMode;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.util.SkyFactory;
import java.util.ArrayList;
import java.util.List;
import jme3test.bullet.BombControl;
import jme3tools.converters.ImageToAwt;
/**
*
-
@author normenhansen
*/
public class main extends SimpleApplication implements ActionListener, PhysicsCollisionListener, AnimEventListener {
private BulletAppState bulletAppState;
//character
CharacterControl character;
Node model;
//temp vectors
Vector3f walkDirection = new Vector3f();
//terrain
RigidBodyControl terrainPhysicsNode;
//Materials
Material matBox, matBoxDone;
//animation
AnimChannel animationChannel;
AnimControl animationControl;
float airTime = 0;
//camera
boolean left = false, right = false, up = false, down = false;
AutoRotateCamera_slim chaseCam;
//explosion
ParticleEmitter effect;
//brick wall
Box brick;
float bLength = 0.8f;
float bWidth = 0.4f;
float bHeight = 0.4f;
FilterPostProcessor fpp;
Node everything;
public static void main(String[] args) {
main app = new main();
app.start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
setupKeys();
createLight();
createSky();
createTerrain();
createCharacter();
setupChaseCamera();
setupAnimationController();
setupFilter();
setupGUI();
}
private void setupGUI(){
this.setDisplayStatView(false);
BitmapText helloText = new BitmapText(guiFont, false);
helloText.setSize(guiFont.getCharSet().getRenderedSize());
helloText.setText(“Hello World”);
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);
System.out.println(guiNode.getChildren().toString());
}
private void setupFilter() {
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
DepthOfFieldFilter doff = new DepthOfFieldFilter();
doff.setFocusDistance(5);
doff.setFocusRange(100);
//fog = new FogFilter();
fpp.addFilter(bloom);
fpp.addFilter(doff);
//fog.setFogDistance(300);
//fog.setFogDensity(1.3f);
// fpp.addFilter(fog);
viewPort.addProcessor(fpp);
}
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
//TONY YOU ARE GOING TO SET UP THE TILE SYSTEM TODAY
private void setupKeys() {
inputManager.addMapping(“wireframe”, new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(this, “wireframe”);
inputManager.addMapping(“CharLeft”, new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(“CharRight”, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(“CharUp”, new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping(“CharDown”, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(“CharSpace”, new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping(“OpenDoor”, new KeyTrigger(KeyInput.KEY_O));
inputManager.addMapping(“CharShoot”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(this, “CharLeft”);
inputManager.addListener(this, “CharRight”);
inputManager.addListener(this, “CharUp”);
inputManager.addListener(this, “CharDown”);
inputManager.addListener(this, “CharSpace”);
inputManager.addListener(this, “OpenDoor”);
inputManager.addListener(this, “CharShoot”);
}
private void createWall() {
float xOff = -144;
float zOff = -40;
float startpt = bLength / 4 - xOff;
float height = 6.1f;
brick = new Box(Vector3f.ZERO, bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
for (int j = 0; j < 15; j++) {
for (int i = 0; i < 4; i++) {
Vector3f vt = new Vector3f(i * bLength * 2 + startpt, bHeight + height, zOff);
addBrick(vt);
}
startpt = -startpt;
height += 1.01f * bHeight;
}
}
private void addBrick(Vector3f ori) {
Geometry reBoxg = new Geometry(“brick”, brick);
reBoxg.setLocalTranslation(ori);
reBoxg.addControl(new RigidBodyControl(1.5f));
reBoxg.setShadowMode(ShadowMode.CastAndReceive);
this.rootNode.attachChild(reBoxg);
this.getPhysicsSpace().add(reBoxg);
}
private void createLight() {
Vector3f direction = new Vector3f(-0.1f, -0.7f, -1);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(direction);
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
}
private void createSky() {
rootNode.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));
}
private void addSquare(Vector3f j, Boolean isReg){
Box flo = new Box(Vector3f.ZERO, 4,0.5f,4);
Geometry flog = new Geometry(“flog”, flo);
if(isReg){
flog.setMaterial(matBox);
}else{
flog.setMaterial(matBoxDone);
}
flog.setLocalTranslation(j);
everything.attachChild(flog);
}
private void createTerrain() {
matBox = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_ml = assetManager.loadTexture(“main/tile.PNG”);
matBox.setTexture(“ColorMap”, tex_ml);
matBoxDone = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_mll = assetManager.loadTexture(“main/tileDone.PNG”);
matBoxDone.setTexture(“ColorMap”, tex_mll);
everything = new Node();
addSquare(Vector3f.ZERO, false);
terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(everything), 0);
everything.addControl(terrainPhysicsNode);
rootNode.attachChild(everything);
getPhysicsSpace().add(terrainPhysicsNode);
}
private void createCharacter() {
CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.5f, 2f);
character = new CharacterControl(capsule, 0.01f);
model = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
model.setName(“model”);
model.setLocalScale(0.5f);
model.addControl(character);
character.setPhysicsLocation(new Vector3f(0, 1, 0));
rootNode.attachChild(model);
getPhysicsSpace().add(character);
}
private void setupChaseCamera() {
flyCam.setEnabled(false);
chaseCam = new AutoRotateCamera_slim(cam, model, inputManager);
}
private void setupAnimationController() {
animationControl = model.getControl(AnimControl.class);
animationControl.addListener(this);
animationChannel = animationControl.createChannel();
}
@Override
public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.2f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.2f);
camDir.y = 0;
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
if (!character.onGround()) {
airTime = airTime + tpf;
} else {
airTime = 0;
}
if (walkDirection.length() == 0) {
if (!“stand”.equals(animationChannel.getAnimationName())) {
animationChannel.setAnim(“stand”, 1f);
}
} else {
character.setViewDirection(walkDirection);
if (airTime > .3f) {
if (!“stand”.equals(animationChannel.getAnimationName())) {
animationChannel.setAnim(“stand”);
}
} else if (!“Walk”.equals(animationChannel.getAnimationName())) {
animationChannel.setAnim(“Walk”, 0.7f);
}
}
character.setWalkDirection(walkDirection);
}
public void onAction(String binding, boolean value, float tpf) {
if (binding.equals(“CharLeft”)) {
if (value) {
left = true;
} else {
left = false;
}
} else if (binding.equals(“CharRight”)) {
if (value) {
right = true;
} else {
right = false;
}
} else if (binding.equals(“CharUp”)) {
if (value) {
up = true;
} else {
up = false;
}
} else if (binding.equals(“CharDown”)) {
if (value) {
down = true;
} else {
down = false;
}
} else if (binding.equals(“CharSpace”)) {
character.jump();
} else if (binding.equals(“OpenDoor”)) {
} else if (binding.equals(“CharShoot”) && !value) {
if(value){
}//else{
//chaseCam.setEnabled(true);
//}
}
}
public void collision(PhysicsCollisionEvent event) {
if(event.getObjectA() instanceof GhostControl){
if(event.getObjectB().getCollisionShape() == character.getCollisionShape()){
System.out.println(“GOGOGOGOGOGO!!!”);
}
}else if(event.getObjectB() instanceof GhostControl){
if(event.getObjectA().getCollisionShape() == character.getCollisionShape()){
System.out.println(“GOGOGOGOGOGO!!!”);
}
}
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
}
}
[/java]
This is the setup/what material (directly from the code):
[java]matBox = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_ml = assetManager.loadTexture(“main/tile.PNG”);
matBox.setTexture(“ColorMap”, tex_ml);
matBoxDone = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_mll = assetManager.loadTexture(“main/tileDone.PNG”);
matBoxDone.setTexture(“ColorMap”, tex_mll);[/java]
I think the reason that it puts the font there is because (from the Console) it gave me “[null (BitmapText), Statistics View (StatsView), null (BitmapText)]” when I ran it… So maybe that’s related. (I put this.setDisplayStatView(false)Any ideas? Thanks.
-NomNom
News:
Okay, so I tried it with the HelloMaterial tut (all I did was replace the first cube code with this: [java]/** A simple textured cube – in good MIP map quality. */
Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
Geometry cube = new Geometry(“My Textured Box”, boxshape1);
Material mat_stl = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
Texture tex_ml = assetManager.loadTexture(“main/tileDone.PNG”);
mat_stl.setTexture(“ColorMap”, tex_ml);
cube.setMaterial(mat_stl);
rootNode.attachChild(cube);[/java])
This is what happens:
It’s when I’m far away, getting closer, and close to it. So yeah… it seems to be reflecting the images around it? It doesn’t happen with the normal ones… any ideas? Thanks.
So, any ideas? Thanks!
-NomNom
wow…that’s strange…you mean you don’t user some red material with transparency right? just a plain textured cube?
Sorry but i’m gonna have to use the “try to update your graphic card drivers” card.
this is really strange
this may or may not help…
Common/MatDefs/Misc/SimpleTextured.j3md = Deprecated: use Unshaded.j3md instead
try this one…
Common/MatDefs/Misc/Unshaded.j3md
ColorMap : Texture is still a material parameter
also, what exactly does the texture file(s) you are trying to apply to the cube look like?
are tile.png & tileDone.png texture atlases?
p.s. i had a funny suspicion that the use of DepthOfFieldFilter mixed with BloomFilter in your main class had something to do with this issue, but i dont see how it would show up in your copy of the HelloMaterial tutorial also.