Package jsynoptic.plugins.java3d

Source Code of jsynoptic.plugins.java3d.Tuple3fData$ColorData

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2007, by :
*     Corporate:
*         EADS Astrium
*     Individual:
*         Claude Cazenave
*
* $Id: Tuple3fData.java,v 1.5 2008/11/06 18:11:21 cazenave Exp $
*
* Changes
* -------
* 11 mars 08  : Initial public release
*
*/
package jsynoptic.plugins.java3d;

import javax.media.j3d.Appearance;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.SceneGraphObject;
import javax.media.j3d.SpotLight;
import javax.vecmath.Vector3f;

import jsynoptic.plugins.java3d.DataAnimator.SourceHolder;


/**
*
*/
public abstract class Tuple3fData extends DoubleDataAnimator.DoubleData {
    static final long serialVersionUID = -7799512766693301184L;

    public Tuple3fData(){
        params=new double[3];
        _sources=new SourceHolder[3];
    }
   
    public void updateFrom(DataAnimator.Data dataCopy) {
        super.updateFrom(dataCopy);
        apply(); // TODO check
    }

    public void set(Values v) {
        set(v.doubleValues, v.data);
    }
   
    public Values get(){
        Values ret=new Values(false);
        ret.doubleValues=getValues();
        ret.data=getDataSources();
       
        return ret;
    }

    public abstract int[] getCapabilities();

    private static final int[] LightDirectionCaps = { DirectionalLight.ALLOW_DIRECTION_WRITE, SpotLight.ALLOW_DIRECTION_WRITE };

    public static class LightDirection extends Tuple3fData {
        static final long serialVersionUID = 8457451778478954317L;
        public void apply() {
            super.apply();
            Vector3f v=new Vector3f((float)params[0], (float)params[1], (float)params[2]);
            for (GraphObjectReference o : getReferences()) {
                if(o.getObject() instanceof DirectionalLight){
                    ((DirectionalLight)o.getObject()).setDirection(v);
                }
                else if(o.getObject() instanceof SpotLight){
                    ((SpotLight)o.getObject()).setDirection(v);
                }
            }
        }
       
        public int[] getCapabilities(){
            return LightDirectionCaps;
        }
    }

    public static final int DIFFUSE=1;
    public static final int AMBIENT=2;
    public static final int SPECULAR=3;
    public static final int EMISSIVE=4;
   
    int[][] ColorCaps = { {Material.ALLOW_COMPONENT_WRITE}};
   
    public static class ColorData extends Tuple3fData {
        int _kind;
       
        public ColorData(int kind){
            _kind=kind;
        }
       
        @Override
        public SceneGraphObject getCapableObject(SceneGraphObject o) {
            if(o instanceof Appearance){
                return ((Appearance)o).getMaterial();
            }
            return super.getCapableObject(o);
        }

        public void apply() {
            super.apply();
            for (GraphObjectReference gor : getReferences()) {
                SceneGraphObject o=getCapableObject(gor.getObject());
                if(o instanceof Material){
                    switch(_kind){
                    case DIFFUSE:
                        ((Material)o).setDiffuseColor((float)params[0], (float)params[1], (float)params[2]);
                        break;
                    case AMBIENT:
                        ((Material)o).setAmbientColor((float)params[0], (float)params[1], (float)params[2]);
                        break;
                    case SPECULAR:
                        ((Material)o).setSpecularColor((float)params[0], (float)params[1], (float)params[2]);
                        break;
                    case EMISSIVE:
                        ((Material)o).setEmissiveColor((float)params[0], (float)params[1], (float)params[2]);
                        break;
                    default:
                        throw new IllegalArgumentException("Unexpcected kind");
                    }
                }
            }
        }
       
        public int[] getCapabilities(){
            return ColorCaps[0];
        }
    }
}
TOP

Related Classes of jsynoptic.plugins.java3d.Tuple3fData$ColorData

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.