Normals useless?

Hi again^^



I think it will not be the last time I have to ask :slight_smile: .

My test classes for vertex and material mutation are working.

Atm I change the normals of a mesh but they didn’t seem to affect the color(for excample).

At first i used SolidColor as usual.

There the changes of the Normal didn’t work.

After that I tryed ShowNormals and the color changes to black like I wanted.



If I remember rightly at jme2 the Normals had allways effect on the color.



What can I do that jme3 allways take notice of them.

[java]

package jme3.own;



import java.io.File;

import java.io.FileNotFoundException;

import java.nio.FloatBuffer;

import java.util.ArrayList;

import java.util.Collection;

import java.util.HashMap;

import java.util.Locale;

import java.util.Scanner;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.TextureKey;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.MatParam;

import com.jme3.material.Material;

import com.jme3.material.MaterialDef;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Mesh;

import com.jme3.scene.VertexBuffer;

import com.jme3.scene.VertexBuffer.Type;

import com.jme3.scene.shape.Box;

import com.jme3.shader.VarType;

import com.jme3.texture.Image;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture2D;



public class MeshNormalsTest extends SimpleApplication {



boolean mutate = false;

boolean alreadyMutated = false;

String path = “/Users/andrevoigt/Documents/workspace/jme3/bin/”;

String matDefName = “Common/MatDefs/Misc/SolidColor.j3md”;

// String matDefName = “Common/MatDefs/Misc/ShowNormals.j3md”;

ArrayList<MaterialVar> materialVars = new ArrayList<MaterialVar>();



@Override

public void simpleInitApp() {

guiNode.detachAllChildren();

viewPort.setBackgroundColor(ColorRGBA.LightGray);

Box box1 = new Box(1, 1, 1);

Geometry geo = new Geometry(“myGeo”, box1);

Material mat1 = new Material(assetManager, matDefName);

mat1.setColor(“m_Color”, ColorRGBA.Blue);



geo.setMaterial(mat1);

rootNode.attachChild(geo);



initKeys();

}



public static void main(String[] args) {

MeshNormalsTest test = new MeshNormalsTest();

test.setShowSettings(false);

test.start();



}



public void initKeys() {

inputManager.addMapping(“Mutate”, new KeyTrigger(KeyInput.KEY_SPACE));

inputManager.addListener(actionListener, new String[] { “Mutate” });



}



private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(“Mutate”) && !keyPressed) {

mutate = true;

}

}

};



public void simpleUpdate(float tpf) {

if (!alreadyMutated) {

if (mutate) {

alreadyMutated = true;

mutate();

}

}

}



private void mutate() {



Geometry geo = ((Geometry) rootNode.getChild(“myGeo”));

Mesh mesh = geo.getMesh();

Material mat = geo.getMaterial();



Collection<MatParam> params = mat.getParams();

ArrayList<MatParam> al = new ArrayList<MatParam>();

al.addAll(params);



for (MatParam matParam : al) {

// System.out.println(matParam.getName());

}



getPossibleParams(mat.getMaterialDef().getAssetName());

for (MaterialVar var : materialVars) {

// System.out.println(var.getVarTypeName() + “(” + var.getType() + “) : " + var.getVarName());

}



// mutation code from here on

// geo.setLocalTranslation(4, 4, -3);

VertexBuffer buffer = mesh.getBuffer(Type.Normal);

FloatBuffer floatBuffer = (FloatBuffer) buffer.getData();



for (int index = 0; index < floatBuffer.capacity(); index++) {

System.out.println(”" + index + “:t” + floatBuffer.get(index));



}

System.out.println("******************");

for (int index = 0; index < floatBuffer.capacity(); index++) {

floatBuffer.put(index, -1);



}

buffer.updateData(floatBuffer);

for (int index = 0; index < floatBuffer.capacity(); index++) {

System.out.println("" + index + “:t” + floatBuffer.get(index));



}

mesh.updateBound();

// geo.setLocalTranslation(new Vector3f(1,1,0));





};



public void getPossibleParams(String defName) {

Scanner scanner = null;

try {

scanner = new Scanner(new File(path + defName));

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

scanner.useLocale(Locale.US);

HashMap<String, VarType> typePairs = new HashMap<String, VarType>();

typePairs.put(“Color”, VarType.Vector4);

for (VarType type : VarType.values()) {

typePairs.put("" + type, type);

}



boolean MaterialParametersFound = false;

while (scanner.hasNext()) {

String sentence = scanner.nextLine();

if (sentence.contains(“MaterialParameters {”)) {

MaterialParametersFound = true;

continue;

}

if (MaterialParametersFound) {

if (sentence.trim().equals("}")) {

MaterialParametersFound = false;

break;

}

String[] parts = sentence.trim().split(" ");

if (typePairs.keySet().contains(parts[0])) {

materialVars.add(new MaterialVar(parts[0], typePairs.get(parts[0]), parts[1]));

} else {

continue;

}

}

}

}

}

[/java]

Normals does not affect SolidColor material.

Only the lighting and normal material uses normal.

Use the lighting.j3md material and instead of mat1.setColor(“m_Color”, ColorRGBA.Blue); use mat1.setColor(“m_Diffuse”, ColorRGBA.Blue);

it should work

thx 2 u