I've had a few people ask whether it's possible to show a fill level in a tank and a recent request made me want to put a formal example together in case it would help anyone else out.
This method uses a texture image and an animated UV layout to get the desired effect. There may be other ways to do this, but this one's the best/only option I know about.
IMPORTANT FILE ATTACHMENT NOTE:
Download the attachment which is a zip file. Inside it, there is a capsule_files.txt file. This file is actually a zip file, so extract it and rename it to capsule_files.zip and unzip it so you will have the files referenced below. Sorry for the weird attachment, but it's the only way I could attach more than three files this post.
- Start of by creating an empty scene using the File -> New menu option.
- Then, Create -> Create Primitive -> Capsule
- The Primitive objects are a nice way to build up an object from more basic objects, but we will just use the capsule for this example.
- Modify the properties of the Capsule by double-clicking on it
- Select the Object tab in the Properties window that appears
- Change the following values using the up/down arrows at the end of their respective line
- Slices: 24
- Stacks: 15
- Leave the Properties window open
- Make sure the capsule is selected and right-click on it and press Tools -> Convert to Polygon Mesh
- This will allow us to create a different UV layout which is required for the effect to work
- Notice in the Properties window, the information for the object changes because we removed all the Primitive information. It's now a dumb mesh object.
- Press Close to close the Properties window
- Press the F key to switch to the Front view
- Download the 01_capsule_mesh.rh file to start from this point
- Turn on the Decal Mapping toolbar
- Press the Settings button on the Decal Mapping toolbar (the last icon that looks like a Play button)
- Uncheck the Apply to Visible Mesh Faces Only
- This is so that the texture will get applied to the back of the capsule also
- Press the OK button to close the Settings window
- Download the capsule.png image
- Press the Load Texture Image button on the Decal Mapping toolbar (the first icon)
- Select the capsule.png image you just downloaded
- Resize the image using the handles and use the middle-mouse wheel to zoom in on the capsule so that the capsule sits entirely inside the light-blue area as closely as possible.
- Once it's lined up, press the Stamp Decal button (the second icon)
- The capsule should now be the nice light-blue color
- Download the 02_capsule_mapped.rh file to start from this point
- While holding down the SHIFT key on the keyboard, double-click on the capsule to open its Material Properties window
- Select the Maps tab of the Material Properties window
- To test our map, change the Offset V value on the right-hand side to -0.5 and you will see it turn dark-blue
- What we want to do now is set up an Animation which controls the Offset V value so we can animate the fill level
- Set the Offset V value back to 0
- Turn on the Animation and Animation Controls Panels
- Create a new Sequence using the Create Sequence button of the Animation panel (the first icon that looks like a movie frame)
- Right-click on the new Sequence-1 sequence and select Properties
- Rename the Sequence to be Capsule
- Change the FPS value to 100 which will also change the End value to 100
- This is so that we will have a smooth transition between values of 0 and 100
- This may seem strange since normal animation FPS values are 30. However, we are using 0-100 to make it easier to set the value from a web page using the API. See the capsule.html file for an example of this.
- Imagine getting a fill level from an external system between 0 and 100. Since the animation length is 100 frames, just set the frame value to the value received from the external system and you're done.
- Press OK to close the Sequence Properties window
- Hold down the SHIFT key and on the Animation Controls Panel, press the Record Keyframes (the red icon with a key on it)
- This will turn the Animation slider Red and move the slider to the last frame (100)
- Using the Material Properties window, change the Offset V value to -0.5
- Press the Record Keyframes button again to turn it off
- Press the Close button on the Material Properties window to close it.
- Now, drag the animation slider back and forth to fill and unfill the capsule.
- Download the 03_capsule_animated.rh file to see the final product
- The final thing would be to create an HTML app to demonstrate it. Run the capsule.html file to see an example.
- The capsule.html file also shows how to access the animations of a scene and to change their CurrentTime value