private Appearance makeAppearance( Material material, Color4f color, boolean transparent ) { Appearance appearance = new Appearance(); appearance .setMaterial( material ); appearance .setCapability( Appearance .ALLOW_MATERIAL_READ ); appearance .setCapability( Appearance .ALLOW_MATERIAL_WRITE ); material .setLightingEnable( true ); Color3f justColor = new Color3f( color .x, color.y, color.z ); appearance .setColoringAttributes( new ColoringAttributes( justColor, ColoringAttributes .SHADE_FLAT ) ); if ( transparent || color.w < 1.0f ) { TransparencyAttributes ta = new TransparencyAttributes(); ta .setTransparencyMode( TransparencyAttributes .BLENDED ); float alpha = transparent? ( PREVIEW_TRANSPARENCY * color.w ) : color.w; ta .setTransparency( PREVIEW_TRANSPARENCY ); appearance .setTransparencyAttributes( ta ); } return appearance; }
/** * Constructs a TextureAttributes object with the specified values. * @param textureMode the texture mode; one of <code>MODULATE</code>, * <code>DECAL</code>, <code>BLEND</code>, <code>REPLACE</code>, or * <code>COMBINE</code> * @param transform the transform object, used to transform texture * coordinates * @param textureBlendColor the texture constant color * @param perspCorrectionMode the perspective correction mode to * be used for color and/or texture coordinate interpolation; * one of <code>NICEST</code> or <code>FASTEST</code> * @exception IllegalArgumentException if <code>textureMode</code> * is a value other than <code>MODULATE</code>, * <code>DECAL</code>, <code>BLEND</code>, <code>REPLACE</code>, or * <code>COMBINE</code> * @exception IllegalArgumentException if mode value is other * than <code>FASTEST</code> or <code>NICEST</code>. */ public TextureAttributes(int textureMode, Transform3D transform, Color4f textureBlendColor, int perspCorrectionMode) { if ((textureMode < MODULATE) || (textureMode > COMBINE)) { throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes10")); } if ((perspCorrectionMode != FASTEST) && (perspCorrectionMode!= NICEST)) { throw new IllegalArgumentException(J3dI18N.getString("TextureAttributes9")); } // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((TextureAttributesRetained)this.retained).initTextureMode(textureMode); ((TextureAttributesRetained)this.retained).initTextureBlendColor(textureBlendColor); ((TextureAttributesRetained)this.retained).initTextureTransform(transform); ((TextureAttributesRetained)this.retained).initPerspectiveCorrectionMode(perspCorrectionMode); }
private void registerTypeHandlers(ComponentLibrary library) { library.registerTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler()); library.registerTypeHandler(Color4f.class, new Color4fTypeHandler()); library.registerTypeHandler(Quat4f.class, new Quat4fTypeHandler()); library.registerTypeHandler(Mesh.class, new AssetTypeHandler(AssetType.MESH, Mesh.class)); library.registerTypeHandler(Sound.class, new AssetTypeHandler(AssetType.SOUND, Sound.class)); library.registerTypeHandler(Material.class, new AssetTypeHandler(AssetType.MATERIAL, Material.class)); library.registerTypeHandler(SkeletalMesh.class, new AssetTypeHandler(AssetType.SKELETON_MESH, SkeletalMesh.class)); library.registerTypeHandler(MeshAnimation.class, new AssetTypeHandler(AssetType.ANIMATION, MeshAnimation.class)); library.registerTypeHandler(Vector3f.class, new Vector3fTypeHandler()); library.registerTypeHandler(Vector2f.class, new Vector2fTypeHandler()); Vector3iTypeHandler vector3iHandler = new Vector3iTypeHandler(); library.registerTypeHandler(Vector3i.class, vector3iHandler); library.registerTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler()); library.registerTypeHandler(Region3i.class, new Region3iTypeHandler(vector3iHandler)); }
protected static String getJmolColorScript(Map<Color4f, List<String>> map) { StringBuilder s = new StringBuilder(); s.append("color cartoons none;"); for (Entry<Color4f, List<String>> entry: map.entrySet()) { s.append("color{"); List<String> ids = entry.getValue(); for (int i = 0; i < ids.size(); i++) { s.append(":"); s.append(ids.get(i)); if (i < ids.size() -1 ) { s.append("|"); } } s.append("}"); s.append(getJmolColor(entry.getKey())); s.append(";"); } return s.toString(); }
public Color4f createColorFromXml(Element node) { try { float r = Float.parseFloat(node.getAttribute("r")); float g = Float.parseFloat(node.getAttribute("g")); float b = Float.parseFloat(node.getAttribute("b")); Color4f col = new Color4f(r, g, b, 1); return col; } catch (Exception e) { return null; } }
ColorRGBA convertColor(Color4f col) { if (col != null) { return new ColorRGBA(col.x, col.y, col.z, col.w); } return null; }
public Vertex copy() { Vertex v = new Vertex(); v.pos = new Vector3D(pos.getX(), pos.getY(), pos.getZ()); v.normal = new Vector3D(normal.getX(), normal.getY(),normal.getZ()); v.color = new Color4f(color.x, color.y, color.z, color.w); v.texcoords = new Vector2D(texcoords.getX(), texcoords.getY()); return v; }
public SlicePlane2DRenderer(View view, Context context, Volume vol) { super(view, context, vol); texVol = new Texture2DVolume(context, vol); for (int i = 0; i < 4; i++) { shapeColrs[i] = new Color4f(); } texAttr.setTextureMode(TextureAttributes.MODULATE); texAttr.setCapability(TextureAttributes.ALLOW_COLOR_TABLE_WRITE); trans.setTransparencyMode(TransparencyAttributes.BLENDED); trans.setSrcBlendFunction(TransparencyAttributes.BLEND_ONE); trans.setDstBlendFunction(TransparencyAttributes.BLEND_ONE); m.setLightingEnable(false); p.setCullFace(PolygonAttributes.CULL_NONE); r.setDepthBufferWriteEnable(false); // these are the default for no texture trans.setTransparency(0.0f); clr.setColor(0.0f, 0.0f, 0.0f); // set up an initial, empty slice sliceGroup.setCapability(Group.ALLOW_CHILDREN_READ); sliceGroup.setCapability(Group.ALLOW_CHILDREN_WRITE); sliceGroup.addChild(null); root.addChild(sliceGroup); numSlicePts = 0; setSliceGeo(); }
private Appearance[][] makeAppearances( Color color ) { float[] rgba = new float[4]; Color4f jColor = new Color4f( color .getRGBColorComponents( rgba ) ); Appearance[][] set = new Appearance[2][2]; for ( int glow = 0; glow < 2; glow++ ) { Material material = makeMaterial( jColor, glow == 1 ); for ( int transp = 0; transp < 2; transp++ ) set [ glow ] [ transp ] = makeAppearance( material, jColor, transp == 1 ); } return set; }
public static Color4f toColor4f( Color color , Color4f result ) { result.x = Math.max( Math.min( color.getRed( ) / 255f , 1f ) , 0f ); result.y = Math.max( Math.min( color.getGreen( ) / 255f , 1f ) , 0f ); result.z = Math.max( Math.min( color.getBlue( ) / 255f , 1f ) , 0f ); result.w = Math.max( Math.min( color.getAlpha( ) / 255f , 1f ) , 0f ); return result; }
public static Appearance shinyAppearance( Color4f color , float shininess ) { final Appearance result = new Appearance( ); final Material mat = new Material( ); mat.setLightingEnable( true ); mat.setShininess( shininess ); result.setMaterial( mat ); setColor( result , color , true ); return result; }
public static Appearance debugAppearance( Color4f color ) { final Appearance result = new Appearance( ); setColor( result , color , false ); setDepthTestFunction( result , RenderingAttributes.ALWAYS ); return result; }
public static void setColorRecursive( Node n , Color4f color , boolean checkMaterial ) { for( final Node node : SceneGraphIterator.boundedIterable( n ) ) { if( node instanceof Shape3D ) { setColor( getAppearance( ( Shape3D ) node ) , color , checkMaterial ); } } }
/** * Gets an RGBA color from the buffer * * @param _nIndex The index of the texture coordinates to change * @param _color Color4f object where the texture coordinates will be stored */ public void getColor(int _nIndex, Color4f _color) { int nIdx = getColorOffset(_nIndex); _color.x = m_colors.get(nIdx + 0); _color.y = m_colors.get(nIdx + 1); _color.z = m_colors.get(nIdx + 2); _color.w = m_colors.get(nIdx + 3); }
/** * Adds a new RGBA color to the buffer * * @param _color Color4f object to add to the vertex buffer */ public void addColor(Color4f _color) { int nIdx = getColorOffset(m_nVertexCount); m_colors.put(nIdx + 0, _color.x); m_colors.put(nIdx + 1, _color.y); m_colors.put(nIdx + 2, _color.z); m_colors.put(nIdx + 3, _color.w); }
/** * Changes the specified RGBA color in the buffer * * @param _nIndex The index of the color to change * @param _color Color4f object to use to change the vertex buffer */ public void setColor(int _nIndex, Color4f _color) { int nIdx = getColorOffset(_nIndex); m_colors.put(nIdx + 0, _color.x); m_colors.put(nIdx + 1, _color.y); m_colors.put(nIdx + 2, _color.z); m_colors.put(nIdx + 3, _color.w); }
protected Object clone() { TextureAttributesRetained tr = (TextureAttributesRetained)super.clone(); tr.transform = new Transform3D(transform); tr.textureBlendColor = new Color4f(textureBlendColor); if (textureColorTable != null) { tr.textureColorTable = new int[textureColorTable.length]; System.arraycopy(textureColorTable, 0, tr.textureColorTable, 0, textureColorTable.length); } else { tr.textureColorTable = null; } // clone the combine mode attributes if (combineRgbSrc != null) { tr.combineRgbSrc = new int[3]; tr.combineAlphaSrc = new int[3]; tr.combineRgbFcn = new int[3]; tr.combineAlphaFcn = new int[3]; for (int i = 0; i < 3; i++) { tr.combineRgbSrc[i] = combineRgbSrc[i]; tr.combineAlphaSrc[i] = combineAlphaSrc[i]; tr.combineRgbFcn[i] = combineRgbFcn[i]; tr.combineAlphaFcn[i] = combineAlphaFcn[i]; } } // other attributes are copied in super.clone() return tr; }
/** * Sets the texture constant color for this * texture attributes object. * @param textureBlendColor the texture constant color * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph */ public void setTextureBlendColor(Color4f textureBlendColor) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_BLEND_COLOR_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("TextureAttributes2")); if (isLive()) ((TextureAttributesRetained)this.retained).setTextureBlendColor(textureBlendColor); else ((TextureAttributesRetained)this.retained).initTextureBlendColor(textureBlendColor); }
public static Color4f[] convertColor4f(Color[] colors) { Color4f[] colors4 = new Color4f[colors.length]; for (int i = 0; i < colors.length; i++) { colors4[i] = convertColor4f(colors[i]); } return colors4; }
public static Color4f deserializeColor4f(final String str) { final float r, g, b, a; try (Scanner s = new Scanner(str);) { r = s.nextFloat(); g = s.nextFloat(); b = s.nextFloat(); if (s.hasNextFloat()) { a = s.nextFloat(); } else { a = 1.0f; } } return new Color4f(r, g, b, a); }
/** * Given a 4-float tuple, converts to an argb value. * * @param c 4-float tuple * @return argb value */ public static int fromColorToARGB(final Color4f c) { final int r = (int) (MAX_RGB_INT_VALUE * c.x); final int g = (int) (MAX_RGB_INT_VALUE * c.y); final int b = (int) (MAX_RGB_INT_VALUE * c.z); final int a = (int) (MAX_RGB_INT_VALUE * c.w); return (a << BIT_SHIFT_ALPHA | r << BIT_SHIFT_RED | g << BIT_SHIFT_GREEN | b); }
/** * Permet de faire une petite classification sur les altitudes des points Il * faut modifier le code pour influer sur cette classification, pour l'instant * Cette classification utilise les véritables altitudes et non les altitudes * exaggarees On utilise une classification linéaire en fonction du tableau de * dégradé utilisé * * @param z l'altitude dont on veut obtenir la couleur * @return la couleur au format Color3f */ public Color4f getColor4f(double z) { // System.out.println("z ="+z+";"+"nodata"+noDataValue); if (z == this.noDataValue) { return new Color4f(1, 0, 0, 0.95f); } // Il s'agit du nombre de couleur que l'on va interprêter comme un // nombre de classes int nbColor = this.color4fShade.length; // la largeur d'une classe double largeur = (this.zMax - this.zMin) / nbColor; int numClass = (int) ((z - this.zMin) / largeur); numClass = Math.max(Math.min(nbColor - 1, numClass), 0); return this.color4fShade[numClass]; }
/** * Permet de faire une petite classification sur les altitudes des points Il * faut modifier le code pour influer sur cette classification, pour l'instant * Cette classification utilise les véritables altitudes et non les altitudes * exaggarees On utilise une classification linéaire en fonction du tableau de * dégradé utilisé * * @param z l'altitude dont on veut obtenir la couleur * @return la couleur au format Color3f */ public Color4f getColor4f(double z) { // System.out.println("z ="+z+";"+"nodata"+noDataValue); if (z == this.noDataValue) { return new Color4f(0, 0, 0, 1.0f); } // Il s'agit du nombre de couleur que l'on va interprêter comme un // nombre de classes int nbColor = this.color4fShade.length; // la largeur d'une classe double largeur = (this.zMax - this.zMin) / nbColor; int numClass = (int) ((z - this.zMin) / largeur); numClass = Math.max(Math.min(nbColor - 1, numClass), 0); return this.color4fShade[numClass]; }
@Override public ScenePart run() { materials.putAll(MaterialsFileReader.loadMaterials("sceneparts/assumeMaterialsFilter.mtl")); Vector3D up = new Vector3D(0, 0, 1); for (Primitive prim : primsIn.mPrimitives) { if (prim.getClass() == Triangle.class) { Triangle tri = (Triangle) prim; double elevation = tri.getCentroid().getZ(); double angle = Vector3D.angle(up, tri.getFaceNormal()) * 180 / Math.PI; // ######### BEGIN Make landcover assumptions based on terrain elevation, slope, angle to sun etc. ########## double snowline_var = 0; double snowline = 0; double timberline = 0; double timber_min_slope = 0; double rock_min_slope = 0; try { snowline = (double) params.get("snowline"); snowline_var = (double) params.get("snowline_var"); timberline = (double) params.get("timberline"); timber_min_slope = (double) params.get("timber_min_slope"); rock_min_slope = (double) params.get("rock_min_slope"); } catch (Exception e) { System.out.println(e.getMessage()); } // Initialize everything with grass: String materialName = "grass"; tri.setAllVertexColors(new Color4f(0.3f, 0.8f, 0.3f, 1f)); // Forest: if (angle > timber_min_slope && elevation < timberline) { materialName = "forest"; tri.setAllVertexColors(new Color4f(0.1f, 0.3f, 0.1f, 1f)); } // Snow: double sunAngle = Vector3D.angle(sunDir.negate(), tri.getFaceNormal()); double temperature = snowline - elevation - snowline_var * sunAngle; if (temperature < 0) { materialName = "snow"; tri.setAllVertexColors(new Color4f(1, 1, 1, 1)); } // Rock: if (angle > rock_min_slope) { materialName = "rock"; tri.setAllVertexColors(new Color4f(0.6f, 0.6f, 0.6f, 1)); } // ######### END Make landcover assumptions based on terrain elevation, slope, angle to sun etc. ########## tri.material = getMaterial(materialName); } } return primsIn; }
public void setAllVertexColors(Color4f color) { verts[0].color = color; verts[1].color = color; verts[2].color = color; }
private void outputShape(OrderedGroup triGroup, int orderDir, TexCoordGeneration tg, Texture2D texture, int numPts, Point3d[] pts, Color4f[] colrs) { count[0] = numPts; TriangleFanArray pgonGeo = new TriangleFanArray(numPts, GeometryArray.COORDINATES | GeometryArray.COLOR_4, count); pgonGeo.setCoordinates(0, pts, 0, numPts); pgonGeo.setColors(0, colrs, 0, numPts); Appearance appearance = new Appearance(); if (texture != null) { appearance.setTextureAttributes(texAttr); appearance.setTexture(texture); } appearance.setMaterial(m); appearance.setColoringAttributes(clr); appearance.setTransparencyAttributes(trans); appearance.setPolygonAttributes(p); appearance.setTexCoordGeneration(tg); appearance.setRenderingAttributes(r); Shape3D shape = new Shape3D(pgonGeo, appearance); Node child = shape; if (outputLines) { Group shapeGroup = new Group(); shapeGroup.addChild(shape); count[0] = numPts + 1; pts[numPts] = pts[0]; LineStripArray lineGeo = new LineStripArray(numPts + 1, GeometryArray.COORDINATES, count); lineGeo.setCoordinates(0, pts, 0, numPts + 1); Appearance lineAppearance = new Appearance(); Shape3D lineShape = new Shape3D(lineGeo, lineAppearance); shapeGroup.addChild(lineShape); child = shapeGroup; } if (verbose) { System.out.println("shape is " + child); } if (orderDir == FRONT) { triGroup.insertChild(child, 0); } else { triGroup.addChild(child); } }
private void colrWeight(Color4f colr, double weight) { colr.x = colr.y = colr.z = colr.w = (float) weight; }
private void colrOneMinusWeight(Color4f colr, double weight) { colr.x = colr.y = colr.z = colr.w = (float) (1.0 - weight); }
public static Appearance flatAppearance( Color4f color ) { final Appearance result = new Appearance( ); setColor( result , color , false ); return result; }
public static void setColor( Shape3D s3D , Color4f color , boolean checkMaterial ) { setColor( getAppearance( s3D ) , color , checkMaterial ); }
/** * Copies all node information from <code>originalNodeComponent</code> into * the current node. This method is called from the * <code>duplicateNode</code> method. This routine does * the actual duplication of all "local data" (any data defined in * this object). * * @param originalNodeComponent the original node to duplicate. * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see NodeComponent#setDuplicateOnCloneTree */ void duplicateAttributes(NodeComponent originalNodeComponent, boolean forceDuplicate) { super.duplicateAttributes(originalNodeComponent, forceDuplicate); TextureAttributesRetained attr = (TextureAttributesRetained) originalNodeComponent.retained; TextureAttributesRetained rt = (TextureAttributesRetained) retained; Color4f c = new Color4f(); attr.getTextureBlendColor(c); Transform3D t = new Transform3D(); attr.getTextureTransform(t); rt.initTextureMode(attr.getTextureMode()); rt.initPerspectiveCorrectionMode(attr.getPerspectiveCorrectionMode()); rt.initTextureBlendColor(c); rt.initTextureTransform(t); if ((attr.getNumTextureColorTableComponents() != 0) && (attr.getTextureColorTableSize() != 0)) { int table[][] = new int[attr.getNumTextureColorTableComponents()][attr.getTextureColorTableSize()]; attr.getTextureColorTable(table); rt.initTextureColorTable(table); } // start fix issue 636 rt.initCombineRgbMode(attr.getCombineRgbMode()); rt.initCombineAlphaMode(attr.getCombineAlphaMode()); rt.initCombineRgbScale(attr.getCombineRgbScale()); rt.initCombineAlphaScale(attr.getCombineAlphaScale()); // Check one of the combine source or function arrays if (attr.combineRgbSrc != null) { for (int i=0; i < 3; i++) { rt.initCombineRgbSource(i, attr.getCombineRgbSource(i)); rt.initCombineAlphaSource(i, attr.getCombineAlphaSource(i)); rt.initCombineRgbFunction(i, attr.getCombineRgbFunction(i)); rt.initCombineAlphaFunction(i, attr.getCombineAlphaFunction(i)); } } // end fix }
public EntityData.Value serialize(Color4f value) { return EntityData.Value.newBuilder().addFloat(value.x).addFloat(value.y).addFloat(value.z).addFloat(value.w).build(); }
public Color4f deserialize(EntityData.Value value) { if (value.getFloatCount() > 3) { return new Color4f(value.getFloat(0), value.getFloat(1), value.getFloat(2), value.getFloat(3)); } return null; }
public Color4f copy(Color4f value) { if (value != null) { return new Color4f(value); } return null; }
public static Color4f convertColor4f(Color color) { return new Color4f(color); }
protected static String getJmolColor(Color4f color) { String hex = Integer.toHexString((color.get().getRGB() & 0xffffff) | 0x1000000).substring(1); return " [x" + hex + "]"; }
public static String serializeColor4f(final Color4f c) { return c.x + " " + c.y + " " + c.z + " " + c.w; }
public BackgroundXml() { color = new Color4f(Color.BLACK); }