Updating the RenderBox library

With the Solar System project implemented and our code stabilized, you might realize that we've built some code that is not necessarily specific to this application, which can be reused in other projects, and ought to make its way back to the RenderBox library. That's what we'll do now.

We recommend you do this directly within Android Studio, selecting and copying from this project's hierarchy view to the other's. Perform the following steps:

  1. Move all the .shader files from the Solar System's res/raw/ directory into the res/raw/ directory of the RenderBox lib's RenderBox module. If you've been following along, there will be eight files for the vertex and fragment .shader files for day_night, diffuse_lighting, solid_color_lighting, and unilt_tex.
  2. Move all the Component and Material .java files from the Solar System's RenderBoxExt module folder to the corresponding folders in RenderBox lib's RenderBox module. Remove all invalid references to MainActivity in the source code.
  3. In the Solar System project, we implemented a method named loadTexture in MainActivity. It rightfully belongs to the RenderBox library. Find the declaration for loadTexture in the Solar System's MainActivity.java file, and cut the code. Then, open the RenderObject.java file in RenderBox lib and paste the definition into the RenderObject class.
  4. In the RenderBox lib, replace (refactor) all the instances of MainActivity.loadTexture with RenderObject.loadTexture. These will be found in several Material Java files, where we load material textures.
  5. In RenderBox.java, the reset() method destroys the handles of any materials. Add the calls for the new materials that we just introduced:
    • DayNightMaterial.destroy()
    • DiffuseLightingMaterial.destroy()
    • SolidColorLightingMaterial.destroy()
    • UnlitTexMaterial.destroy()
  6. Resolve any package name mismatches, and fix any other compile-time errors, including removing any references to solarsystem throughout.

Now, you should be able to successfully rebuild the library (Build | Make Module 'renderbox') to generate an updated renderbox[-debug].aar library file.

Lastly, the Solar System project can now use the new .aar library. Copy the renderbox[-debug].aar file from the RenderBoxLib project's renderbox/build/output folder into the SolarSystem renderbox/ folder, replacing the older version of the same file with the newly built one. Build and run the Solar System project with this version of the library.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset