/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package fi.vtt.simantics.processeditor.animations; import org.simantics.db.Graph; import org.simantics.db.Resource; import org.simantics.proconf.g3d.base.JmeRenderingComponent; import com.jme.renderer.ColorRGBA; import fi.vtt.simantics.processeditor.stubs.PipeRun; // TODO : this class won't work with valueSets public class ResourcePipeAnimationController extends PipeAnimationController { Resource color; Resource velocity; ColorRGBA minColor = new ColorRGBA(0.f,0.f,1.f,1.f); ColorRGBA maxColor = new ColorRGBA(1.f,0.f,0.f,1.f); ColorRGBA currentColor = new ColorRGBA(1.f,1.f,1.f,1.f); double colorMin; double colorMax; double iColorRange; double velMin; double velMax; double iVelRange; public ResourcePipeAnimationController(JmeRenderingComponent component, PipeRun pipeline, Resource color,double colorMin, double colorMax, Resource velocity, double velMin, double velMax) { super(component, pipeline); this.color = color; this.velocity = velocity; this.colorMin = colorMin; this.colorMax = colorMax; this.iColorRange = 1.0/(colorMax-colorMin); this.velMin = velMin; this.velMax = velMax; this.iVelRange = 1.0/(velMax-velMin); } private double getVelocity(Graph graph) { return graph.getScalarDouble(velocity); //velocity.getDoubleScalarValue(); } private double getColor(Graph graph) { return graph.getScalarDouble(color); } public void updateAnimation(Graph g,double frameTime) { double d = (getVelocity(g)-velMin)*iVelRange; float f = (float)((getColor(g)-colorMin)*iColorRange); currentColor.interpolate(minColor, maxColor, f); for (PipeFlowAnimation a : animatables) { a.animate(d,frameTime); //a.getParticleGeometry().setDefaultColor(currentColor); a.getParticleGeometry().setStartColor(currentColor); a.getParticleGeometry().setEndColor(currentColor); } } }