use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class MaterialTest method material.
private void material(String path) {
AssetManager assetManager = TestUtil.createAssetManager();
material = new Material(assetManager, path);
geometry.setMaterial(material);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class LoadJ3mdTest method testShaderNodesMaterialDefLoading.
@Test
public void testShaderNodesMaterialDefLoading() {
supportGlsl(100);
material("testMatDef.j3md");
material.selectTechnique("Default", renderManager);
assertEquals(material.getActiveTechnique().getDef().getShaderNodes().size(), 2);
Shader s = material.getActiveTechnique().getDef().getShader(TestUtil.createAssetManager(), myCaps, material.getActiveTechnique().getDynamicDefines());
assertEquals(s.getSources().size(), 2);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method loadObjects.
private void loadObjects(FbxElement element) throws IOException {
FbxObject obj = null;
for (FbxElement e : element.children) {
switch(e.id) {
case "Geometry":
FbxMesh mesh = new FbxMesh(this, e);
obj = mesh;
if (mesh.geometries != null)
geomMap.put(mesh.id, mesh);
break;
case "Material":
obj = new FbxMaterial(this, e);
break;
case "Model":
FbxNode node = new FbxNode(this, e);
obj = node;
modelMap.put(node.id, node);
if (node.isLimb())
limbMap.put(node.id, node);
break;
case "Pose":
FbxBindPose pose = new FbxBindPose(this, e);
obj = pose;
bindMap.put(pose.id, pose);
break;
case "Texture":
obj = new FbxTexture(this, e);
break;
case "Video":
obj = new FbxImage(this, e);
break;
case "Deformer":
obj = loadDeformer(e);
break;
case "AnimationLayer":
FbxObject layer = new FbxObject(this, e);
obj = layer;
alayerMap.put(layer.id, layer);
break;
case "AnimationCurve":
obj = new FbxAnimCurve(this, e);
break;
case "AnimationCurveNode":
obj = new FbxAnimNode(this, e);
break;
default:
obj = null;
}
if (obj != null)
allObjects.put(obj.id, obj);
}
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class ParticlesModifier method postMeshCreationApply.
@Override
public void postMeshCreationApply(Node node, BlenderContext blenderContext) {
LOGGER.log(Level.FINE, "Applying particles modifier to: {0}", node);
MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
ParticleEmitter emitter = particleEmitter.clone();
// veryfying the alpha function for particles' texture
Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE;
char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1);
if (nameSuffix == 'B' || nameSuffix == 'N') {
alphaFunction = MaterialHelper.ALPHA_MASK_NONE;
}
// removing the type suffix from the name
emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1));
// applying emitter shape
EmitterShape emitterShape = emitter.getShape();
List<Mesh> meshes = new ArrayList<Mesh>();
for (Spatial spatial : node.getChildren()) {
if (spatial instanceof Geometry) {
Mesh mesh = ((Geometry) spatial).getMesh();
if (mesh != null) {
meshes.add(mesh);
Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
// TODO: divide into several pieces
emitter.setMaterial(material);
}
}
}
if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) {
((EmitterMeshVertexShape) emitterShape).setMeshes(meshes);
}
node.attachChild(emitter);
}
use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.
the class Face method loadAll.
/**
* Loads all faces of a given mesh.
* @param meshStructure
* the mesh structure we read the faces from
* @param userUVGroups
* UV groups defined by the user
* @param verticesColors
* the vertices colors of the mesh
* @param temporalMesh
* the temporal mesh the faces will belong to
* @param blenderContext
* the blender context
* @return list of faces read from the given mesh structure
* @throws BlenderFileException
* an exception is thrown when problems with file reading occur
*/
public static List<Face> loadAll(Structure meshStructure, Map<String, List<Vector2f>> userUVGroups, List<byte[]> verticesColors, TemporalMesh temporalMesh, BlenderContext blenderContext) throws BlenderFileException {
LOGGER.log(Level.FINE, "Loading all faces from mesh: {0}", meshStructure.getName());
List<Face> result = new ArrayList<Face>();
MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
if (meshHelper.isBMeshCompatible(meshStructure)) {
LOGGER.fine("Reading BMesh.");
Pointer pMLoop = (Pointer) meshStructure.getFieldValue("mloop");
Pointer pMPoly = (Pointer) meshStructure.getFieldValue("mpoly");
if (pMPoly.isNotNull() && pMLoop.isNotNull()) {
List<Structure> polys = pMPoly.fetchData();
List<Structure> loops = pMLoop.fetchData();
for (Structure poly : polys) {
int materialNumber = ((Number) poly.getFieldValue("mat_nr")).intValue();
int loopStart = ((Number) poly.getFieldValue("loopstart")).intValue();
int totLoop = ((Number) poly.getFieldValue("totloop")).intValue();
boolean smooth = (((Number) poly.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
Integer[] vertexIndexes = new Integer[totLoop];
for (int i = loopStart; i < loopStart + totLoop; ++i) {
vertexIndexes[i - loopStart] = ((Number) loops.get(i).getFieldValue("v")).intValue();
}
// uvs always must be added wheater we have texture or not
Map<String, List<Vector2f>> uvCoords = new HashMap<String, List<Vector2f>>();
for (Entry<String, List<Vector2f>> entry : userUVGroups.entrySet()) {
List<Vector2f> uvs = entry.getValue().subList(loopStart, loopStart + totLoop);
uvCoords.put(entry.getKey(), new ArrayList<Vector2f>(uvs));
}
List<byte[]> vertexColors = null;
if (verticesColors != null && verticesColors.size() > 0) {
vertexColors = new ArrayList<byte[]>(totLoop);
for (int i = loopStart; i < loopStart + totLoop; ++i) {
vertexColors.add(verticesColors.get(i));
}
}
result.add(new Face(vertexIndexes, smooth, materialNumber, uvCoords, vertexColors, temporalMesh));
}
}
} else {
LOGGER.fine("Reading traditional faces.");
Pointer pMFace = (Pointer) meshStructure.getFieldValue("mface");
List<Structure> mFaces = pMFace.isNotNull() ? pMFace.fetchData() : null;
if (mFaces != null && mFaces.size() > 0) {
// indicates if the material with the specified number should have a texture attached
for (int i = 0; i < mFaces.size(); ++i) {
Structure mFace = mFaces.get(i);
int materialNumber = ((Number) mFace.getFieldValue("mat_nr")).intValue();
boolean smooth = (((Number) mFace.getFieldValue("flag")).byteValue() & 0x01) != 0x00;
int v1 = ((Number) mFace.getFieldValue("v1")).intValue();
int v2 = ((Number) mFace.getFieldValue("v2")).intValue();
int v3 = ((Number) mFace.getFieldValue("v3")).intValue();
int v4 = ((Number) mFace.getFieldValue("v4")).intValue();
int vertCount = v4 == 0 ? 3 : 4;
// uvs always must be added wheater we have texture or not
Map<String, List<Vector2f>> faceUVCoords = new HashMap<String, List<Vector2f>>();
for (Entry<String, List<Vector2f>> entry : userUVGroups.entrySet()) {
List<Vector2f> uvCoordsForASingleFace = new ArrayList<Vector2f>(vertCount);
for (int j = 0; j < vertCount; ++j) {
uvCoordsForASingleFace.add(entry.getValue().get(i * 4 + j));
}
faceUVCoords.put(entry.getKey(), uvCoordsForASingleFace);
}
List<byte[]> vertexColors = null;
if (verticesColors != null && verticesColors.size() > 0) {
vertexColors = new ArrayList<byte[]>(vertCount);
vertexColors.add(verticesColors.get(v1));
vertexColors.add(verticesColors.get(v2));
vertexColors.add(verticesColors.get(v3));
if (vertCount == 4) {
vertexColors.add(verticesColors.get(v4));
}
}
result.add(new Face(vertCount == 4 ? new Integer[] { v1, v2, v3, v4 } : new Integer[] { v1, v2, v3 }, smooth, materialNumber, faceUVCoords, vertexColors, temporalMesh));
}
}
}
LOGGER.log(Level.FINE, "Loaded {0} faces.", result.size());
return result;
}
Aggregations