-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase.java
38 lines (35 loc) · 1.89 KB
/
Base.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package SimulazioneEsame;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import java.awt.*;
public class Base extends Box {
public Base(float xdim, float ydim, float zdim){
// Box(float xdim, float ydim, float zdim, int primflags, Appearance ap)
super(xdim,ydim,zdim,Primitive.GENERATE_NORMALS, createAppearance());
}
public static Appearance createAppearance() {
PolygonAttributes polyAttrbutes = new PolygonAttributes();
Appearance appearance = new Appearance();
Material material = new Material();
//The PolygonAttributes object defines attributes for rendering polygon primitives.
polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
appearance.setPolygonAttributes(polyAttrbutes);
material.setCapability(Material.AMBIENT_AND_DIFFUSE);
material.setAmbientColor(210 / 255f, 180 / 255f, 140 / 255f);
material.setDiffuseColor(210 / 255f, 180 / 255f, 140 / 255f);
// Caricamento Texture
TextureLoader loader = new TextureLoader("C:\\Users\\utente\\IdeaProjects\\Java3D\\src\\images\\wood.jpg", "RGB", new Container());
Texture texture = loader.getTexture();
TextureAttributes textureAttributes = new TextureAttributes();
textureAttributes.setTextureMode(TextureAttributes.COMBINE);
TexCoordGeneration texCoordGeneration = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_3);
appearance.setTexCoordGeneration(texCoordGeneration);
appearance.setTexture(texture);
appearance.setTextureAttributes(textureAttributes);
appearance.setMaterial(material);
return appearance;
}
}