use of maspack.render.ColorMapProps 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;
}
use of maspack.render.ColorMapProps in project artisynth_core by artisynth.
the class GL2Viewer method drawText.
public double drawText(Font font, String str, float[] pos, double emSize) {
if (font == null) {
font = getDefaultFont();
}
boolean savedBlending = isBlendingEnabled();
boolean savedTexture = isTextureMappingEnabled();
boolean savedDepth = isDepthWriteEnabled();
BlendFactor dfactor = getBlendDestFactor();
BlendFactor sfactor = getBlendSourceFactor();
setDepthWriteEnabled(false);
setBlendingEnabled(true);
setBlendSourceFactor(BlendFactor.GL_SRC_ALPHA);
setBlendDestFactor(BlendFactor.GL_ONE_MINUS_SRC_ALPHA);
setTextureMappingEnabled(true);
ColorMapProps savedTextureProps = setColorMap(myTextTextureProps);
maybeUpdateState(gl);
activateTexture(gl, myTextRenderer.getTexture());
myTextRenderer.begin(gl);
double d = myTextRenderer.drawText(font, str, pos, (float) emSize);
myTextRenderer.end(gl);
deactivateTexture(gl);
setDepthWriteEnabled(savedDepth);
setBlendSourceFactor(sfactor);
setBlendDestFactor(dfactor);
setBlendingEnabled(savedBlending);
setTextureMappingEnabled(savedTexture);
setColorMap(savedTextureProps);
return d;
}
Aggregations