StdDraw3D

StdDraw3D: Texturing

Introduction

In this tutorial we will be covering texturing a sphere using the StdDraw3D library.

What You Will Need to Start

For this tutorial you will need to have completed the basic setup for a Java3D application, you will need to import all of the libraries that Java3D applications require. If you haven’t done that and don’t know how to do that, click here to find out how. You will also need to have imported the StdDraw3D class into your project, click here to find out how.

Implementation

Wrapping a texture around a sphere using the StdDraw3D library is very simple, all it takes is an additional argument when creating the sphere.

First of all let’s find a texture that we want to use and add it into the project folder. Grab any texture from any website, I’m using a texture of the Earth. Then in the root folder for the project create a folder named ‘res’. Then inside that folder add your texture.

If you cannot find a texture you could use this texture here. This is an 8k texture so is rather large. It is not recommended that you use 8k textures if you are animating the shape.

a96fde8b9b084517a2e0d43dd949614e

We can then store this directory within a string. We can then call this variable to wrap the texture around a shape.

7b9125dd0ea740dcb1bccf9d38e4c5ae

To wrap a texture around the sphere, the single line of code below is used.

a2f2fb823bf94af9afa3bac4d239280a

The code below is all the code that is needed to texture a sphere.

ef275412de50479f826bdba33108b78d

Finally, the finished program will display a 3D sphere with a texture wrapped.

77c0aa12d367441a9be59423b85cb31d

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s