package nl.tudelft.simulation.dsol.animation.D3; import java.awt.geom.Point2D; import java.rmi.RemoteException; import java.util.Enumeration; import javax.media.j3d.BranchGroup; import javax.media.j3d.Group; import javax.media.j3d.Node; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.naming.Context; import javax.naming.NamingException; import javax.vecmath.AxisAngle4d; import javax.vecmath.Vector3d; import nl.tudelft.simulation.dsol.animation.Locatable; import nl.tudelft.simulation.dsol.animation.StaticLocation; import nl.tudelft.simulation.dsol.logger.SimLogger; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.language.d3.DirectedPoint; import nl.tudelft.simulation.naming.context.ContextUtil; /** * Renderable3D, a 3d renderable. *
* Copyright (c) 2002-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights * reserved. See for project information * https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can * be found at * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Roy Chin */ public abstract class Renderable3D extends BranchGroup implements Renderable3DInterface { /** the source of this animatableObject. */ protected Locatable source = null; /** the simulator. */ protected SimulatorInterface simulator = null; /** Rotation group. */ protected TransformGroup locationGroup = null; /** Type of renderable (world, static or simulated. */ protected int type = Renderable3DInterface.DYNAMIC_OBJECT; /** * Scale: temporary solution This scale is used to scale translations and can also be used to scale the model * (shape). This is a temporary solution as we would actually like to scale the entire content branch, but this is * not possible yet */ protected double scale = 1.0d; /** translation Used in update; put here to prevent garbage. */ private Transform3D translate = new Transform3D(); /** combined rotation angle Used in update; put here to prevent garbage. */ private Transform3D rotate = new Transform3D(); /** yaw angle Used in update; put here to prevent garbage. */ private Transform3D yaw = new Transform3D(); /** pitch angle Used in update; put here to prevent garbage. */ private Transform3D pitch = new Transform3D(); /** roll angle Used in update; put here to prevent garbage. */ private Transform3D roll = new Transform3D(); /** * @param simulator SimulatorInterface */ public Renderable3D(final SimulatorInterface simulator) { if (!Locatable.class.isAssignableFrom(this.getClass())) { throw new IllegalArgumentException("this class should implement Locatable interface"); } this.source = (Locatable) this; this.simulator = simulator; this.initialize(); } /** * @param staticLocation Point3d * @param simulator SimulatorInterface */ public Renderable3D(final DirectedPoint staticLocation, final SimulatorInterface simulator) { super(); this.source = new StaticLocation(staticLocation, null); this.simulator = simulator; this.type = Renderable3DInterface.STATIC_OBJECT; this.initialize(); } /** * @param staticLocation Point3d * @param branchGroup A branchGroup containing (a part of) the model * @param simulator SimulatorInterface */ public Renderable3D(final DirectedPoint staticLocation, final BranchGroup branchGroup, final SimulatorInterface simulator) { super(); this.source = new StaticLocation(staticLocation, null); this.simulator = simulator; this.type = Renderable3DInterface.STATIC_OBJECT; this.initializeTransformGroups(); this.provideModel(this.locationGroup); this.addChild(this.locationGroup); this.addChild(branchGroup); this.update(); try { Context context = ContextUtil.lookup(this.simulator.getReplication().getContext(), "/animation/3D"); ContextUtil.bind(context, this); } catch (NamingException exception) { SimLogger.always().warn(exception, "