use of maspack.render.NormalMapProps in project artisynth_core by artisynth.
the class TextureEgyptianTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
JFrame frame = new JFrame();
JPanel controls = new JPanel();
frame.add(controls);
PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
true);
RenderProps rprops = plane.getRenderProps();
if (rprops == null) {
rprops = new RenderProps();
}
rprops.setShading(Shading.SMOOTH);
rprops.setShininess(20);
rprops.setFaceColor(new Color(155, 196, 30));
rprops.setSpecular(new Color(255, 113, 0));
rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
String srcDir = PathFinder.findSourceDir(this);
ColorMapProps dprops = new ColorMapProps();
dprops.setFileName(srcDir + "/data/specular_map.jpg");
dprops.setColorMixing(ColorMixing.MODULATE);
dprops.setEnabled(true);
NormalMapProps normalProps = new NormalMapProps();
normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
normalProps.setScaling(0.3f);
normalProps.setEnabled(true);
BumpMapProps bumpProps = new BumpMapProps();
bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
bumpProps.setScaling(2.5f);
bumpProps.setEnabled(true);
rprops.setColorMap(dprops);
rprops.setNormalMap(normalProps);
rprops.setBumpMap(bumpProps);
// FixedMeshBody fm = new FixedMeshBody(plane);
// fm.setRenderProps(rprops);
mv.addRenderable(plane);
if (false) {
mv.addRenderable(new IsRenderable() {
@Override
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d.X_UNIT.updateBounds(pmin, pmax);
Point3d.Y_UNIT.updateBounds(pmin, pmax);
Point3d.Z_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
}
@Override
public void render(Renderer renderer, int flags) {
renderer.setColor(Color.CYAN);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.drawSphere(Point3d.ZERO, 1);
}
@Override
public void prerender(RenderList list) {
// TODO Auto-generated method stub
}
@Override
public int getRenderHints() {
// TODO Auto-generated method stub
return 0;
}
});
}
mv.autoFitViewers();
LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
controls.add(base);
base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
controls.add(base);
base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
controls.add(base);
frame.pack();
frame.setVisible(true);
}
use of maspack.render.NormalMapProps in project artisynth_core by artisynth.
the class PolygonalMeshRenderer method drawFaces.
private void drawFaces(Renderer renderer, RenderProps props, boolean highlight, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
boolean useTextures = robj.hasTextureCoords();
Renderer.FaceStyle savedFaceStyle = renderer.getFaceStyle();
Shading savedShadeModel = renderer.getShading();
Shading shading = props.getShading();
if (!robj.hasNormals() && shading != Shading.FLAT) {
shading = Shading.NONE;
}
renderer.setShading(shading);
renderer.setFaceColoring(props, highlight);
// XXX always front and back when selecting?
if (renderer.isSelecting()) {
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
} else {
renderer.setFaceStyle(props.getFaceStyle());
}
// int i = 0; // i is index of face
ColorInterpolation savedColorInterp = null;
if (usingHSV(getMesh())) {
savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(-1);
}
ColorMapProps oldtprops = null;
NormalMapProps oldnprops = null;
BumpMapProps oldbprops = null;
if (useTextures) {
ColorMapProps dtprops = props.getColorMap();
oldtprops = renderer.setColorMap(dtprops);
NormalMapProps ntprops = props.getNormalMap();
oldnprops = renderer.setNormalMap(ntprops);
BumpMapProps btprops = props.getBumpMap();
oldbprops = renderer.setBumpMap(btprops);
}
if (renderer.isSelecting() && featureSelection) {
for (int i = 0; i < features.numFeatures(); ++i) {
renderer.beginSelectionQuery(features.getFeature(i));
renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.TRIANGLES);
renderer.endSelectionQuery();
}
} else {
renderer.drawVertices(robj, features.getVertices(), DrawMode.TRIANGLES);
}
if (useTextures) {
// restore diffuse texture properties
renderer.setColorMap(oldtprops);
renderer.setNormalMap(oldnprops);
renderer.setBumpMap(oldbprops);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(0);
}
if (savedColorInterp != null) {
renderer.setColorInterpolation(savedColorInterp);
}
renderer.setFaceStyle(savedFaceStyle);
renderer.setShading(savedShadeModel);
}
use of maspack.render.NormalMapProps in project artisynth_core by artisynth.
the class WavefrontReader method processMaterialLine.
protected boolean processMaterialLine(ReaderTokenizer rtok, RenderProps props) throws IOException {
// int lineno = rtok.lineno();
if (rtok.sval.equals("Ka")) {
// ambient colour
double r = rtok.scanNumber();
double g = rtok.scanNumber();
double b = rtok.scanNumber();
if (props != null) {
props.setFaceColor(new Color((float) r, (float) g, (float) b));
// System.out.println( props.getFaceColor().toString() );
}
} else if (rtok.sval.equals("Kd")) {
// diffuse colour
double r = rtok.scanNumber();
double g = rtok.scanNumber();
double b = rtok.scanNumber();
if (props != null) {
props.setFaceColor(new Color((float) r, (float) g, (float) b));
// System.out.println( props.getFaceColor().toString() );
}
} else if (rtok.sval.equals("Ks")) {
// specular colour
double r = rtok.scanNumber();
double g = rtok.scanNumber();
double b = rtok.scanNumber();
props.setSpecular(new Color((float) r, (float) g, (float) b));
} else if (rtok.sval.equals("d") || rtok.sval.equals("Tr")) {
String a = rtok.sval;
double alpha = rtok.scanNumber();
if (props != null) {
if (a.equals("d")) {
props.setAlpha(alpha);
} else {
props.setAlpha(1 - alpha);
}
}
} else if (rtok.sval.equals("Ns")) {
double shininess = rtok.scanNumber();
if (props != null) {
props.setShininess((float) shininess);
}
} else // eg map_Kd lenna.tga # the diffuse texture map
if (rtok.sval.equals("map_Kd") || rtok.sval.equals("map_Ka")) {
// we need period
int savePeriod = rtok.getCharSetting('.');
rtok.wordChar('.');
int saveDash = rtok.getCharSetting('-');
rtok.wordChar('-');
String map = rtok.scanWord();
if (map != null) {
// set texture properties
props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
props.setShading(Shading.SMOOTH);
ColorMapProps tprops = props.getColorMap();
if (tprops == null) {
tprops = new ColorMapProps();
}
tprops.setFileName(currPath + "/" + map);
tprops.setEnabled(true);
tprops.setColorMixing(ColorMixing.MODULATE);
props.setColorMap(tprops);
}
// restore period state
rtok.setCharSetting('.', savePeriod);
rtok.setCharSetting('-', saveDash);
} else // eg map_Kd lenna.tga # the diffuse texture map
if (rtok.sval.equals("bump") || rtok.sval.equalsIgnoreCase("map_bump")) {
// we need period
int savePeriod = rtok.getCharSetting('.');
rtok.wordChar('.');
int saveDash = rtok.getCharSetting('-');
rtok.wordChar('-');
String map = rtok.scanWord();
if (map != null) {
// set texture properties
props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
props.setShading(Shading.SMOOTH);
BumpMapProps tprops = props.getBumpMap();
if (tprops == null) {
tprops = new BumpMapProps();
}
tprops.setFileName(currPath + "/" + map);
tprops.setEnabled(true);
props.setBumpMap(tprops);
}
// restore period state
rtok.setCharSetting('.', savePeriod);
rtok.setCharSetting('-', saveDash);
} else if (rtok.sval.equals("norm") || rtok.sval.equalsIgnoreCase("map_norm")) {
// we need period
int savePeriod = rtok.getCharSetting('.');
rtok.wordChar('.');
int saveDash = rtok.getCharSetting('-');
rtok.wordChar('-');
String map = rtok.scanWord();
if (map != null) {
// set texture properties
props.setFaceStyle(Renderer.FaceStyle.FRONT_AND_BACK);
props.setShading(Shading.SMOOTH);
NormalMapProps tprops = props.getNormalMap();
if (tprops == null) {
tprops = new NormalMapProps();
}
tprops.setFileName(currPath + "/" + map);
tprops.setEnabled(true);
props.setNormalMap(tprops);
}
// restore period state
rtok.setCharSetting('.', savePeriod);
rtok.setCharSetting('-', saveDash);
} else {
return false;
}
return true;
}
Aggregations