Welcome!

Java IoT Authors: Zakia Bouachraoui, Liz McMillan, Kevin Benedict, Elizabeth White, Yeshim Deniz

Related Topics: Java IoT

Java IoT: Article

Star Trek Technology for Java3D

Building a particle system for Java3D

The Star Trek universe has inspired many technology ideas but I'm disappointed I don't have a transporter yet. One Star Trek technology that has been available for sometime is the particle system. No, this is not an exotic propulsion system for your flying car. The particle system was invented to animate the Genesis effect in Star Trek II: The Wrath of Khan. While the Genesis device was used to transform a barren planet into one full of life, we can adopt this technology for more modest effects in Java3D.

In the Beginning
In previous articles, we've focused on creating planetary surfaces with Java3D. One challenging area of graphics programming is rendering irregular or ill-defined objects like clouds, smoke, or fireworks. William Reeves faced that challenge when Lucasfilm was asked to create a planetary creation effect called the Genesis effect for Star Trek II: Wrath of Khan. The idea was that a planet would be hit with a missile that would transform it from a barren wasteland into one full of life. Explosions and flames on a planetary scale gave birth to a new form of animation called a particle system.

Reeves' original paper (see references) describes a particle system as one defined by clouds of primitive particles or points in three dimensions. These particles change and move with time making a particle system dynamic. How a particle changes or moves is based on a controlled stochastic process giving it a natural look. How particles evolve in a particle system is called the particle life cycle.

Your morning shower is just like a particle system. Particles are born and emitted by the system. Where the particles are born and where they are headed is assigned by the particle system. Your plumbing system determines the water temperature and velocity of the droplets. Particles exist and change under the influence of external forces. The room temperature and gravity affect how the water changes temperature and where it collides with you or the tub. So where does that fancy stochastic process come into play? To make the rate of particle emission, ejection angle, velocity, or any other attribute more interesting we need to vary them in slightly unpredictable ways. Reeves described the approach of adding a randomly selected variance to the central value of an attribute:

Attribute = CentralAttibuteValue + Random() * AttributeVariance

This approach can be applied to just about any attribute of the particle or the particle system. Figure 1 provides a simple example. The particle system evolves over time by repeating a series of steps and varying the attributes along the way. The steps are:

  1. New particles are initialized and emitted using varying attributes.
  2. Particles past their life expectancy die and are removed.
  3. Surviving particles are updated based on external forces, velocity, etc.
  4. The particles are rendered.
This cycle is repeated until the particle system has no more particles or lives beyond its lifetime. That's all you need to know to get started building a particle system, so let's build one for Java3D.

Transporting to Java3D
Before we build the particle system in Java3D, let's lay out the objectives. First of all, the particle system should be easy to add to the scene graph just like any other Java3D shape. We should allow the Java3D TransformGroup to be used to position and orient the particle system. The design should allow us to use anything from pixels to Shade3D objects for our particles. The particles should be emitted from a variety of nozzle shapes and be affected by external forces like wind or gravity. These objectives should give us the flexibility to graduate from simple water fountain particle systems to tornado simulations. Before we jump straight into an F5 tornado, let's get a simple spray working.

Figure 2 is a subset of a design that satisfies our particle system objectives. It's probably easiest to describe it from the bottom up so let's start with the Particle object. This obviously represents a particle in the particle system and logically maintains its position, velocity, and acceleration. I used the word "logically" because I am fibbing a bit to make it easier to describe. A ParticleEmitter object emits particles and controls the movement of the particles as you might expect. The particle emitter delegates the initial position of particles to a GenerationShape object. During the animation cycle, ExternalInfluence objects such as Gravity affect the particles. All of these objects are independent of Java3D so they could be used in other environments as well. Now I'm going to fess up about the particle location. The location of a particle is actually maintained by the particle emitter. This is done so that the locations of all particles can be shared in one array for use in a Java3D specific Shape3D implementation of a particle system.

Do You Have a Point, Spock?
So far we have satisfied just a few of our objectives. Let's use the particle emitter to make a single Shape3D particle system. We can do this by making ParticleSystem a subclass of the Shape3D class and using a PointArray for the geometry. Luckily for us, the particle emitter has a float array of particle locations that will fit nicely into a PointArray. This geometry class is about the simplest supported by Java3D, accepting a float value for each x, y and z location of the point. The geometry needs to change as the particles move so this means that this particle system should implement the GeometryUpdater interface. If you're not familiar with how to change the geometry of a Java3D shape during runtime, refer back to my previous article ("Casting Perlin's Movie Magic in Java3D" [JDJ, Vol. 10, issue 3]) for an overview. The last piece of the design is the ParticleSystemManager that is responsible for notifying the particle systems to run through their life-cycle steps. Before we dig into the details of how it works, have a look at two of the examples included in the source code and shown in Figure 3.

The particle system is created in Listing 1. The particle emitter is created with a point generation shape having a spread angle of 45 degrees, and specific central and variance values for emission rate, initial velocity, and particle lifetime. We fade the particles by adding the FadePoint influence to the particle emitter (one of many influence objects included in the source code). This influence gradually changes the transparency of the particle as it ages. Now the particle system is created with the emitter and a green particle color. Adding the particle system to the scene graph is not shown due to space constraints, but it's added just like any other Java3D shape. Finally the particle system manager is added to the scene graph and the animation begins.

The ParticleSystemManager is a Java3D behavior that notifies all active particle systems after a specified time has elapsed. I covered behaviors and their use in animation in my previous article so refer back to it if you need a refresher. This implementation uses a combination of elapsed frames and time to create a stable animation cycle. The particle system manager starts and maintains the Reeves particle system life cycle.

More Stories By Mike Jacobs

Mike Jacobs is technology architect and Technology Fellow focused on using technology to improve health care.

Comments (10)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists examined how DevOps helps to meet the de...
According to Forrester Research, every business will become either a digital predator or digital prey by 2020. To avoid demise, organizations must rapidly create new sources of value in their end-to-end customer experiences. True digital predators also must break down information and process silos and extend digital transformation initiatives to empower employees with the digital resources needed to win, serve, and retain customers.
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, will provide an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life ...
Smart Cities are here to stay, but for their promise to be delivered, the data they produce must not be put in new siloes. In his session at @ThingsExpo, Mathias Herberts, Co-founder and CTO of Cityzen Data, discussed the best practices that will ensure a successful smart city journey.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
LogRocket helps product teams develop better experiences for users by recording videos of user sessions with logs and network data. It identifies UX problems and reveals the root cause of every bug. LogRocket presents impactful errors on a website, and how to reproduce it. With LogRocket, users can replay problems.
@CloudEXPO and @ExpoDX, two of the most influential technology events in the world, have hosted hundreds of sponsors and exhibitors since our launch 10 years ago. @CloudEXPO and @ExpoDX New York and Silicon Valley provide a full year of face-to-face marketing opportunities for your company. Each sponsorship and exhibit package comes with pre and post-show marketing programs. By sponsoring and exhibiting in New York and Silicon Valley, you reach a full complement of decision makers and buyers in ...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Data Theorem is a leading provider of modern application security. Its core mission is to analyze and secure any modern application anytime, anywhere. The Data Theorem Analyzer Engine continuously scans APIs and mobile applications in search of security flaws and data privacy gaps. Data Theorem products help organizations build safer applications that maximize data security and brand protection. The company has detected more than 300 million application eavesdropping incidents and currently secu...
Rafay enables developers to automate the distribution, operations, cross-region scaling and lifecycle management of containerized microservices across public and private clouds, and service provider networks. Rafay's platform is built around foundational elements that together deliver an optimal abstraction layer across disparate infrastructure, making it easy for developers to scale and operate applications across any number of locations or regions. Consumed as a service, Rafay's platform elimi...