Sie sind auf Seite 1von 46

Parametric Curve and Surface Modeling on a

Tablet PC

A Thesis
Presented to
the Faculty of the College of Computer Studies
De La Salle University Manila

In Partial Fulfillment
of the Requirements for the Degree of
Bachelor of Science in Computer Science

by

CANOSO, Candice Patricia

Dr. Florante R. Salvador


Adviser

December 11, 2016


Abstract

This research project tackles 3D modeling for Android tablet PCs with a fo-
cus on parametric curves and surfaces, and as well as implement a proper user
interface for curve and surface manipulation. This research extends the features
implemented in Gesture based 3D mesh modeling(Carlos, Jr., Sanchez, & To-
lentino, 2012) to parametric curves - specifically Bezier, B-Spline, NURBS and
Subdivision Curves - and as well as to parametric surfaces - specifically Bezier,
B-Spline, NURBS and Subdivision Surfaces. The tools that will be used for this
research are OpenGL ES 2.0 (Khronos Group, 2015) and Android Studio. The
software and prototypes will be tested on 8” to 10” sized Android tablets.

Keywords: Computer Graphics, 3D Modeling, Parametric Curves, Para-


metric Surfaces, Subdivision Surfaces
Contents

1 Research Description 1

1.1 Overview of the Current State of Technology . . . . . . . . . . . . 1

1.2 Research Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.2.1 General Objective . . . . . . . . . . . . . . . . . . . . . . . 2

1.2.2 Specific Objectives . . . . . . . . . . . . . . . . . . . . . . 3

1.3 Scope and Limitations of the Research . . . . . . . . . . . . . . . 3

1.4 Significance of the Research . . . . . . . . . . . . . . . . . . . . . 4

1.5 Research Methodology . . . . . . . . . . . . . . . . . . . . . . . . 4

1.5.1 Research Activities . . . . . . . . . . . . . . . . . . . . . . 4

1.5.2 Calendar of Activities . . . . . . . . . . . . . . . . . . . . 7

2 Review of Related Literature 9

2.1 Review of Related Paper . . . . . . . . . . . . . . . . . . . . . . . 9

2.1.1 User Interfaces/Experience (UI/UX) . . . . . . . . . . . . 9

2.2 Review of Related Software . . . . . . . . . . . . . . . . . . . . . 11

2.2.1 3D Modeling Mobile Applications . . . . . . . . . . . . . . 11

2.2.2 OpenGL ES . . . . . . . . . . . . . . . . . . . . . . . . . . 12

ii
3 Theoretical Framework 15

3.1 Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.1.1 Linear Interpolation . . . . . . . . . . . . . . . . . . . . . 15

3.1.2 Bezier Curves . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.1.3 Basis-Spline (B-Spline) Curves . . . . . . . . . . . . . . . . 19

3.1.4 Non-Uniform Rational Basis-Spline (NURBS) Curves . . . 20

3.2 Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.2.1 Subdivision Surface . . . . . . . . . . . . . . . . . . . . . . 21

3.3 Winged-Edge Data Structure . . . . . . . . . . . . . . . . . . . . 23

3.4 Basic 3D Modeling Concepts . . . . . . . . . . . . . . . . . . . . . 24

3.4.1 Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.4.2 3D Modeling Transformations and Representations . . . . 25

4 The Point Modeler 2.0 System 27

4.1 System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.2 System Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.3 System Scope and Limitations . . . . . . . . . . . . . . . . . . . . 28

4.4 Architectural Design . . . . . . . . . . . . . . . . . . . . . . . . . 28

4.4.1 Data Structure Module . . . . . . . . . . . . . . . . . . . . 30

4.4.2 Abstraction of OpenGL . . . . . . . . . . . . . . . . . . . 30

4.5 System Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

4.5.1 Main Functions . . . . . . . . . . . . . . . . . . . . . . . . 32

4.5.2 Miscellaneous Functions . . . . . . . . . . . . . . . . . . . 33

4.6 Physical Environment and Resources . . . . . . . . . . . . . . . . 34

iii
A OpenGL ES 2.0 Draw Requirements 35

References 39

iv
List of Figures

2.1 A brochure for Gesture Based 3D Modeling (Carlos et al., 2012) . 10

2.2 Screenshots of 3D Creationist, Subdiv Former and Qubism from


left to right. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.1 A line segment that starts with P0 , ends with P1 , and interpolated
by P(t) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.2 The 3rd level of subdivision for different values for t . . . . . . . . 16

3.3 The 3 levels of subdivision of a Cubic Bezier Curve where t = 0.5 17

3.4 A cubic B-spline curve with 7 control points (D0 to D6 ), 4 Bezier


curve segments, and 11 knots (u0 to u10 ) (Farin, 1996) . . . . . . 19

3.5 Screenshots of applying the subdivision algorithm to a cube from


Blender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.6 A sample rectangular mesh (Catmull & Clark, 1978) . . . . . . . 21

3.7 An illustration of the winged-edge representation of edge a on a cube 23

3.8 A cube and its sub-parts . . . . . . . . . . . . . . . . . . . . . . . 24

4.1 An overview of the architectural design of Point Modeler 2.0 . . 29

4.2 A simple class diagram depicting some interactions of the datastructure


package of Point Modeler 2.0 . . . . . . . . . . . . . . . . . . . . 30

4.3 A simple class diagram depicting some interactions of the drawables


package of Point Modeler 2.0 . . . . . . . . . . . . . . . . . . . . 31

v
List of Tables

1.1 Timetable of Activities for 2016 . . . . . . . . . . . . . . . . . . . 8

2.1 Operations available on the sample 3D modeling applications . . . 13

2.2 Programmable Graphic-Rendering API vs. Fixed-Function Graphic-


Rendering API . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3.1 The edge table entries for edge a in Figure 3.7 . . . . . . . . . . . 24

vi
Chapter 1

Research Description

This chapter gives an overview of the topic. A short introduction, the scope and
objectives, and the methodology is found in this chapter.

1.1 Overview of the Current State of Technology

Along with the computer and computer graphics, the mobile phone also has its
share of evolution. In its earlier stages, the only popular function of mobile phones
are for calling and sending text messages. Today, in the smartphone era, the phone
is not only expected as a medium for communication, but for learning, earning as
well as for gaming and recreation made possible using mobile applications.

A number of mobile applications that offers 3D modeling experience is already


available in Google’s Playstore and Apple’s Appstore (ie. as of 2016, the number
applications in Google Playstore that supports manipulation of a model in 3D
space exceeds 10). These mobile applications features a variety of gamified to
recreational 3D modeling. A few notable examples of these mobile applications
are 3D Creationist (3D Creationist, 2016), Subdiv Former (ASCON, 2016) and
Qubism (Quinn, 2016).

These applications offer a variety of user interfaces and 3D transformations


/ tools: 3D Creationist (3D Creationist, 2016) provides pre-defined polygon-
s/meshes that the user can add to the 3D world as a part of a model/world. These
polygons are then applied some basic 3D modeling transformations (translate,
scale, rotate) and coloring to shape the model/world. Subdiv Former (ASCON,
2016), on the other hand, only offers a spherical mesh to be modified by the user

1
accordingly. While the model is limited to what the user can make-up from a
sphere, this application offers more advanced tools such as extrusion/intrusion,
subdivision, split, and etc. on top of the basic 3D transformation. Lastly, Qubism
(Quinn, 2016) offers 3D modeling by combining together and modifying cubes.
This application offers basic 3D modeling transformation to a single or a set of
cubes as well as transformation of a selected cube to a predefined shape.

A more detailed discussion of 3D modeling mobile applications is given in


Section 2.2.1.

Blender (Blender Foundation, 2016) is a popular and widely-used open source


3D modeling software for laptops/desktops. Being a full-scaled 3D modeling soft-
ware, Blender has an implementation on various functionalities for curves and
surfaces. Examples of these are:

• Bezier Curves

• Non-uniform Rational Basis Splines (NURBS) Curves, Surfaces and various


other geometries

• Curve Extrusion

• Subdivision Surfaces

Carlos et al. (2012), a BSCS undergraduate research project, has already im-
plented a 3D modeling application that provides basic functionalities for creation/-
modification/deletion of vertices. This thesis is an extension of their research to
parametric curves and surfaces. While the applications mentioned previously
provides a functionality for pre-defined curved meshes, the product application of
this research project will primarily be focused on parametric curves and surface
modeling.

1.2 Research Objectives

1.2.1 General Objective

To model parametric curves and surfaces on a tablet PC

2
1.2.2 Specific Objectives

1. To review papers on modeling parametric curves and surfaces.


2. To survey existing 3D modeling mobile applications.
3. To study OpenGL ES (Khronos Group, 2015) and Android Development
Tools for mobile devices.
4. To implement parametric curves and surfaces on a tablet PC.
5. To survey the implemented mobile application on its usability and first use
ease.

1.3 Scope and Limitations of the Research

Parametric curves and surfaces to be reviewed are limited to the following specifics:

Curves Surfaces
• Bezier Curve • Bezier Surface
• B-Splines / NURBS Curve • B-Splines / NURBS Surface
• Subdivision Curve • Subdivision Surface

While the topic of this thesis is focused on curves and surfaces, 3D modeling for
mobile applications (consisting of mobile phone and tablet applications) in general
is considered for surveying. This is for comparing and obtaining a baseline on the
functionalities and user interface implemented on these mobile applications.

Only OpenGL ES 2.0 (Khronos Group, 2015) and its dependencies as well
as Android Studio will be studied. These said dependencies consists of function-
s/methods of previous OpenGL versions that are also implemented in OpenGL
ES 2.0 (Khronos Group, 2015); and are considered only because of poor docu-
mentation on OpenGL ES 2.0 (Khronos Group, 2015). Also, OpenGL aspects are
limited to the basic functionalities for manipulating vertices, edges and basic col-
oring/shading. These said aspects include the following dependencies: OpenGL
matrices, essential/basic pipeline programming (needed only for OpenGL ES 2.0),
renderers, camera and perspectives.

Functionalities of the system consists of, but not limited to, the curves and
surfaces reviewed. Along with this, implementation of a data structure or a pack-
age that could abstract the requirements and practices of these said tools from
the requirements of the system is also considered. Additional implementations

3
include: winged-edge data structure (Baumgart, 1972), basic 3D modeling trans-
formations, saving, loading and exporting of data, and a workable user interface
for 3D modeling.

This research also gives as much importance to the usability of the imple-
mented application. Therefore, a survey on the usability and first use ease of the
prototypes and final product will be conducted to determine its standing on the
mentioned matters. The survey will consist of various users testing the application
through completing a single or a series of simple modeling tasks. Modeling task
will vary from modeling a simple cube to modeling certain objects/animals. Test
users will vary from students, hobbyist and a seasoned 3D modeler.

1.4 Significance of the Research

This research project adds some curves and surface functionalities to its predeces-
sor, Carlos et al. (2012)’s Gesture Based 3D Mesh Modeling.

There are very few 3D modeling applications available for mobile devices and
even fewer 3D modeling applications that support curves and surfaces. The prod-
uct application of this research project, upon extension, could lead to even more
detailed and complex 3D modeling for mobile devices compared to the gamified
or recreational 3D modeling applications that are currently being offered.

The final software could also be potentially deployed to Google’s Playstore for
various users to benefit from; as well as made available on Github for possible
further extension from interested parties.

1.5 Research Methodology

1.5.1 Research Activities

The steps and activities that have been and will be performed to accomplish the
objectives are the following:

• Review of Related Works

• Initial System Design and Prototyping

4
• Consultation and Finalization of Functionalities

• Software Development and Documentation

• Alpha and Beta Testing

Review of Related Works

This step is the very first and the core and foundation of the research. The
step is basically understanding the technicalities of the thesis as well as drawing
inspiration for the final product.

Related Literature and Necessary Topics The following topics - basic 3D


modeling concepts, basic 3D modeling transformations, Bezier and B-Spline Curves
and Bezier Surfaces - has already been first studied in a certain Computer Graphics
(GRAPHIX) class.

Carlos et al. (2012)’s Gesture Based 3D Mesh Modeling has been used as the
starting point for references and sub-topics to be reviewed. These references/sub-
topcs consisted of the following: sketch-based 3D modeling, the vertex-vertex
data structure, winged-edged data structure, and their system - Point: A Gesture
Based 3D Modeling tool.

Additionally, Catmull and Clark (1978)’s implementation of Subdivision Sur-


faces has also been reviewed in preparation for the Initial prototyping stage.

Other subjects that will be reviewed are NURBS, Subdivision Curve, B-Spline
Surface and NURBS Surface.

Related Software Related software has been reviewed, as well as critiqued


and compared (see Section 2.2), as a reference or a baseline for functionalities and
user interface. These software includes Gesture Based 3D Mesh Modeling (Carlos
et al., 2012), 3D Creationist (3D Creationist, 2016), Qubism (Quinn, 2016) and
SubDivFormer (ASCON, 2016).

Initial System Design and Prototyping

The initial prototype was made to familiarize with OpenGL and the Android
platform. Due to the technical difficulty of OpenGL ES 2.0 (Khronos Group,

5
2015), this step took longer than the others. The length of the time on which
to learn OpenGL was the reason for a system design that abstracts or wraps, as
much as possible, all the OpenGL calls to a set of classes for easier reference.

The initial prototype is also the deliverable for the THSST-1 Software Proto-
type. This step applies the knowledge gained from the previous step, Review of
Related Works.

The initial system design covers the class structure, data structure to use for
3D data (Winged-Edged Data Structure (Baumgart, 1972)) and implementation
of Bezier Curves and Subdivision Surfaces; however, with limitations in basic 3D
modeling transformations, proper gestures and a proper user interface.

Consultation and Finalization of Functionalities

The previous steps, Review of Related Works and Initial System Design and Pro-
totyping, are steps to grasp an idea or inspiration to this thesis’ final application
deliverable. The target implemented 3D curves and surfaces (see Section 1.3) are
finalized in this step from a consultation with the adviser.

Other aspects of the application to be finalized are the following:

• User Interface

• User Actions (how could the user model, what can the user control or do)

• Application Assets

• Gestures supported

These aspects revolve on the usability and user appeal of the software and will
be finalized in THSST-2 along with the System Design Implementation step.

Software Development and Documentation

The Agile software development life cycle will be used for this thesis. This is the
cause of why some aspects of the target application enumerated in the previous
step, Consultation and Finalization of Functionalities, have intentionally not been
finalized.

6
This step is allotted for the whole of THSST-2. Several prototypes will be
submitted to the adviser and various testers, and modified accordingly based on
the said testers’ recommendations.

The actions that will be performed, each prototype and its specifications as
well as challenges/bugs and changes in the prototype will be recorded for docu-
mentation purposes. The source code will be uploaded to Github to keep track of
the time allotted for each prototype.

The final prototype of this step will be the deliverable for THSST-2

Alpha and Beta Testing

Alpha testing is done later in THSST-2 and the whole of THSST-3 by the proponent
of the thesis as well as the adviser and testers to catch any undetected bugs and
for quality assurance. The software in this step should be in at least a “nearly
fully-usable” state. Tests for this step is focused on the functionalities and a few
final modifications on user interface.

The Beta testing, also done in THSST-3, is done by potential users of the
mobile application such as students, recreational 3D modelers and other interested
parties. The application, in this step, should be in release state that could readily
be uploaded to Google’s Playstore. This step is aimed to get user feedback and
the first use ease of the mobile application.

1.5.2 Calendar of Activities

Table 1.1 shows a Gantt chart of the activities. Each bullet represents approxi-
mately one week worth of activity.

7
Table 1.1: Timetable of Activities for 2016
Activities (2016) Jan Feb Mar Apr May Oct Nov Dec Jan Feb Mar Apr
Review of Related Works •• •• • ••••
Initial System Design and •••• ••
Prototyping

8
Consultation and Finaliza- • • • • • • •
tion of Functionalities
Software Development and • •••• •••• •••• •••• • • • •
Documentation
Alpha and Beta Testing •• •••• •••• • •
Documentation • •••• •• • • • •• • •• •• •
Chapter 2

Review of Related Literature

This chapter discusses the features, capabilities, and limitations of existing re-
search, algorithms, or software that are related/similar to the thesis.

2.1 Review of Related Paper

2.1.1 User Interfaces/Experience (UI/UX)

Sketch-based 3D Modeling

“Sketching is a natural way to communicate ideas quickly: with only a few pencil
strokes, complex shapes can be evoked in viewers” - this is how Olsen, Samavati,
Sousa, and Jorge (2009) started their paper. It was followed by a statement
pointing out that the creation of 3D models is often slowed down by complex
3D modeling systems because of its high learning curve. The goal, then, of the
Sketch-Based Interface for Modeling (SBIM) research is to combine both the ex-
presomsive power and control of WIMP-based systems and the expeditious and
natural interaction of sketching. Although this kind of interface has gained re-
search interest, it has not yet been able to replace industry systems because it
lacks the functionalities that a full-featured WIMP-based 3D modeling software
would have.

9
Figure 2.1: A brochure for Gesture Based 3D Modeling (Carlos et al., 2012)

Gesture Based 3D Mesh Modeling

A brochure of their system is illustrated in Figure 2.1. The thesis preceding


this is a research on Gesture-based 3D mesh modeling (Carlos et al., 2012). Its
final product is a 3D modeling mobile application for Android Tablets with a
sketch-based mesh modeling interface. Their study includes, as their research title
suggests, determining appropriate gestures for the creation and manipulation of
the following 3D data: vertices, edges, faces and meshes only.

Their mobile application’s functionalities are listed as follows (Note that a


geometry could be a single or a set of vertices and edges as well as complex
meshes):

• Create Geometry • Scale Geometry


• Select Geometry • Rotate Geometry
• Translate Geometry • Change View

10
• Save Geometry • Delete Geometry
• Load Geometry

Their system functions are focused, but without limitation, on basic modeling
transformations (translation, scaling and rotation). Carlos et al. (2012), however,
did not include textures, lighting and shaders in their scope.

For development, Carlos et al. (2012) have used the Android SDK tools as well
as OpenGL ES 1.0. Their mobile application was tested on two Samsung GT-1000
Android tables and an Asus Eeepad Transformaer Android tablet although there
was no mention on the OS version of Android it was tested on. It has also been
tested and expected to be used by those who have little or no background in 3D
modeling.

2.2 Review of Related Software

2.2.1 3D Modeling Mobile Applications

Figure 2.2: Screenshots of 3D Creationist, Subdiv Former and Qubism from left
to right.

11
There already exists several 3D modeling mobile applications on Google’s Play-
store. A few notable applications, as earlier mentioned, are 3D Creationist (3D
Creationist, 2016), Subdiv Former (ASCON, 2016) and Qubism (Quinn, 2016).
These applications are notable for this research project because of their similarity
to Point Modeler 2.0 in functionality and in user interface. Table 2.1 shows the
similarity of the 3 applications, Point (Carlos et al., 2012) and Point Modeler 2.0.

Candidate features/interfaces from these mobile applications that would be


appropriated to Point Modeler 2.0 are the following:

• 3D Creationist (3D Creationist, 2016)’s interface for basic modeling trans-


formations. A selected object in the model has 3 arrows corresponding to
the x, y, z axes. These arrows are to be interacted with to perform the
selected transformation along the selected axis.

• 3D Creationist (3D Creationist, 2016)’s grid plane that the camera’s Look
At is set to. This grid is set as the platform of the model as well as not to
confuse the camera orientation.

• Camera controls shared by all 3 apps (3D Creationist, 2016)(ASCON, 2016)(Quinn,


2016). Swipe left/right to rotate the camera along the y-axis and swipe up-
/down to rotate the camera along the x -axis.

2.2.2 OpenGL ES

OpenGL ES (Khronos Group, 2015) is a subset from the larger OpenGL 2.0 API
discussed above and is optimized for resource constrained display devices such as
smartphones, tablets and gaming consoles. As of October 2012, more than 90%
of Android devices were already running OpenGL ES 2.0 (Mehta, 2013) while
well known companies such as Apple, Inc., NVIDIA Corporation, Intel, Pana-
sonic, Sony Computer Entertainment, Google, Inc., AMD, Samsung Electronics,
and many more (Khronos Group, 2015) have made use of OpenGL ES for their
products at no cost in license fees.

OpenGL ES 2.0 (Khronos Group, 2015) is released as a programmable graphic-


rendering API which contrasts to OpenGL ES 1.x as a fixed-function graphic-
rendering API. Mehta (2013) discusses the difference of OpenGL ES 2.0 from
OpenGL ES 1.0 in Table 2.2.

12
Table 2.1: Operations available on the sample 3D modeling applications
Mobile Applications
Operations/Features 3D Creationist SubDiv Former Qubism Point Point Modeler 2.0
Basic Transformations (Translate, Rotate, Scale) • • • • •
Extrude/Intrude •
Split • •
Add Initial Meshes • • •

13
Colors/Shading • • •
Subdivision • •
Camera Manipulation • • • • •
Edit Tools (Create/Delete/Undo/Redo) • • • • •
Multiple Selection • • • • •
Selection Tools (Duplicate/Copy/Paste) • • •
Save/Load • • • •
Export •
Table 2.2: Programmable Graphic-Rendering API vs. Fixed-Function Graphic-
Rendering API
Property Fixed-Function Pipeline Programmable Pipeline
Other names Fixed-Function Graphic- Programmable Graphic-
Rendering API Rendering API
OpenGL ES re- 1.0 2.0
lease
Rendering func- Hard-coded and unmodifi- Programmable and flexible
tions and algo- able device-provided algo- rendering functions
rithm rithms
Access to under- Does not provide develop- Provides developers full ac-
lying hardware ers with access to underlying cess to underlying hardware
hardware through shaders
Graphics card Uses special purpose graph- Uses general purpose graph-
ics card ics card
Complexity Graphics hardware could be Slower than the fixed-
optimized for faster render- function pipeline; however,
ing offers more enhanced graph-
ics rendering

14
Chapter 3

Theoretical Framework

This chapter discusses the topics that are to be reviewed upon as mentioned in
Section 1.2.2. The topics discussed are as shown in (Farin, 1996).

3.1 Curves

3.1.1 Linear Interpolation

Figure 3.1: A line segment that starts with P0 , ends with P1 , and interpolated by
P(t)

Let P0 be a point starting a line segment; P1 , a point ending the line segment;
and P(t), a point along the line segment such that 0 ≤ t ≤ 1 (Refer to Figure 3.1
for an illustration of this line segment).

Using ratio and proportion, we get this following equation:

t−0 P(t) − P0
= (3.1)
1−t P1 − P(t)

15
We manipulate Equation 3.1 to isolate P(t) on the left hand side to yield:

P(t) = (1 − t)P0 + tP1 (3.2)

The resulting formula in Equation 3.2 is called the Linear Interpolation Equa-
tion. This states that given P0 , P1 and a value for t, we could compute for P(t) -
a point interpolating the given end points P0 and P1 .

3.1.2 Bezier Curves

Bezier curves are a series of repetitive linear interpolation between n + 1 con-


trol points where n is the degree of the Bezier curve or the maximum level of
subdivisions to get the final point Pn (t).

Bezier curves can be generally broken down into 4 steps:

Step 1 Interpolate the line segments connecting the control points: P0 and P1 ,
P1 and P2 . . . Pn and Pn+1
Step 2 Interpolate the line segments connecting the new points yielded from the
previous level of subdivision.
Step 3 Repeat Step 2 n − 2 times
Step 4 Repeat from Step 1 for the different values of t as seen in Figure 3.2

Figure 3.2: The 3rd level of subdivision for different values for t

The result of the interpolations made from the line segments are denoted as
Pab where a denotes the level of subdivision and b denotes the subscript of the
starting point of the line segment being interpolated. The point yielded from the
last level of subdivision Pn0 is the value of Pn (t)

16
Example: Cubic Bezier Curves

To further explain Bezier Curves, we will use Cubic Bezier Curves of degree 3 and
4 control points P0 , P1 , P2 and P3 .

Figure 3.3: The 3 levels of subdivision of a Cubic Bezier Curve where t = 0.5

Cubic bezier curves have 3 levels of subdivision as described below:

1st Level of Subdivision Given the control points and a value for t, we first
interpolate the line segments connecting the control points. This yields
new points P10 from the line segment connecting P0 and P1 , P11 from the
line segment connecting P1 and P2 , and finally P12 from the line segment
connecting P2 and P3 .
Applying the Linear Interpolation Equation in Equation 3.2, we get the
following:

P10 = (1 − t)P0 + tP1 (3.3)


P11 = (1 − t)P1 + tP2 (3.4)
P12 = (1 − t)P2 + tP3 (3.5)

2nd Level of Subdivision We then interpolate the line segments connecting


the points yielded from the first level of subdivision. This yields new points
P20 from the line segment connecting P10 and P11 , and P21 from the line segment
connecting P11 and P12 .
Applying the Linear Interpolation Equation in Equation 3.2, we get the
following:

P20 = (1 − t)P10 + tP11 (3.6)


P21 = (1 − t)P11 + tP12 (3.7)

17
3rd Level of Subdivision Finally, we interpolate the line segment connecting
P20 and P21 to get P30 .
Applying the Linear Interpolation Equation in Equation 3.2, we get the
following:

P30 = (1 − t)P20 + tP21 (3.8)

Because this is the last level of subdivision for Cubic Bezier Curves, P(t)
gets the value of P30 .

Pn (t) = P30 (3.9)

Substituting the values from Equations 3.3 to 3.9, we get the following final
equation of P(t) relative to P0 , P1 , P2 and P3 .

Pn (t) = (1 − t)3 P0 + 3t(1 − t)2 P1 + 3t2 (1 − t)P2 + t3 P3 (3.10)

The de Casteljau Algorithm

The algorithm above is called the de Casteljau Algorithm. The previously de-
scribed repeated interpolation step is generalized in this algorithm for an arbitrary
degree n as follows:

Given: P0 , P1 ...Pn ∈ E3 and t ∈ R

Set:


r=1,. . . ,n
Pri = (1 − t)Pr−1
i (t) + tPr−1
i+1 (t) (3.11)
i = 0 , . . . , n-r

and
P0i (t) = Pi
Pn0 (t) = Pn (t)

The Bernstein Form of a Bezier Curve

Generalizing the equation in (3.10), the point on the Bezier Curve Pn (t) is ex-
pressed as:

18
n
X
n
P (t) = Pn0 = Pj Bjn (t) (3.12)
j=0

where Bjn (t) is the Bernstein polynomial defined explicitly by:

 
n j
Bjn (t) = t (1 − t)n−j (3.13)
j

and the binomial coefficients are given by:


n!
  
n j!(n−j)!
if 0 ≤ j ≤ n
= (3.14)
j 0 else

3.1.3 Basis-Spline (B-Spline) Curves

A B-Spline Curve is a generalization of a Bezier Curve. A single B-spline curve


of degree m with n control points would have n - m bezier curve segments. A
sample b-spline curve could be seen in Figure 3.4. These segments are separated
by a point called knots. A b-spline curve has n + m + 1 non-decreasing knots
stored in the knot vector.

Figure 3.4: A cubic B-spline curve with 7 control points (D0 to D6 ), 4 Bezier curve
segments, and 11 knots (u0 to u10 ) (Farin, 1996)

The knots in the B-spline curve could change the parametric segments longer
or shorter. Knot vectors which have equal distances between each knots are called
uniform; conversely, non equal distances between each knots are otherwise called

19
non-uniform. The example in Figure 3.4 is an example of a non-uniform B-spline
curve.

The Basis Function

Given:

• A degree m
• n control points (D0 , D1 , ..., Dn−1 )
• The knot vector (u0 , u1 , ..., un+m )

The B-Spline Curve C m (u) could be expressed as:


n−1z
X
m
C (u) = Di Ni,m (u) (3.15)
i=0

where Ni,m (u) is the basis function defined by:


1 if ui ≤ u < ui+1
Ni,0 (u) =
0 otherwise
u − ui ui+j+1 − u
Ni,j (u) = Ni,j−1 + Ni+1,j−1 (3.16)
ui+j − ui ui+j+1 − ui+1

and j = 1, 2, ..., m

3.1.4 Non-Uniform Rational Basis-Spline (NURBS) Curves

A NURBS Curve is an extension of a non-uniform B-spline curve. This implies


that the control points will have weights attached to each of them that would in-
fluence a particular curve segment on the control point that the weight is attached
to.

The NURBS Curve C m (u) could be expressed as:

Pn−1
m i=0 wi Di Ni,m (u)
C (u) = P n−1 (3.17)
i=0 wi Ni,m (u)

20
3.2 Surfaces

3.2.1 Subdivision Surface

Subdivision Surface is a method for smoothing out a mesh by iteratively subdivid-


ing the mesh creating new and smaller faces. The illustration in Figure 3.5 shows
the per iteration of smoothing out a cube into a sphere using this algorithm. More
iterations of the subdivision surface algorithm applied to the mesh creates more
and smaller new faces which results to smoother looking surfaces.

Figure 3.5: Screenshots of applying the subdivision algorithm to a cube from


Blender

Catmull and Clark’s Subdivision Surface Algorithm

Figure 3.6: A sample rectangular mesh (Catmull & Clark, 1978)

Catmull and Clark (1978)’s algorithm for the subdivision surface requires the
computation of the following:

21
• Face Points. For every face of the mesh, a new face point is created. A face
point is defined as the average of all the vertices making up the face.
Referring to the sample patch in Figure 3.6, face point Q11 is defined as
follows:
P11 + P12 + P21 + P22
Q11 = (3.18)
4
• Edge Points. For every edge of the mesh, a new edge point is created. An
edge point is defined as the average of the midpoint of the old edge with the
average of the two new face points neighboring the edge.
Referring to the sample patch in Figure 3.6, edge point Q12 is defined as
follows:

Q11 +Q13 P12 +P22


2
+ 2
Q12 = (3.19)
2
where Q11 and Q13 are the face points neighboring the edge connecting P12
and P22

• Vertex Points. For every vertex of the mesh, a new vertex point is created.
a vertex point is defined as follows:

Q 2R S(n − 3)
+ + (3.20)
n n n
where
Q = the average of the new face points of all faces adjacent to the old vertex
point.
R = the average of the midpoints of all edges incident on the old vertex
point.
S = the old vertex point
n = the total number of faces touching the old vertex point

Referring to the sample patch in Figure 3.6, vertex point Q22 is defined as
follows:

Q R P22
Q22 = + + (3.21)
4 2 4
where
Q11 + Q13 + Q31 + Q33
Q=
4
and
P22 +P12 P22 +P21 P22 +P32 P22 +P23
2
+ 2
+ 2
+ 2
R=
4

22
These new points will then be connected by the following rules:

• The new face points connect to the new edge points of the old edges defining
the old face.

• The new vertex points connect to the new edge points of the old edges
incident on the old vertex point.

3.3 Winged-Edge Data Structure

Figure 3.7: An illustration of the winged-edge representation of edge a on a cube

A 3D model represented by the Winged-Edge Data Structure (Baumgart, 1972)


uses edges to keep track of its elements. This datastructure uses an edge table to
keep track of all the edges in the model. Each entry in the edge table consists of
the following:

• The edge

• Vertices of the edge

• Faces adjacent to the edge (left face and right face)

• Predecessor and successor edge when traversing the left face clockwise

• Predecessor and successor edge when traversing the right face clockwise

A sample edge table entry is illustrated in Figure 3.7 .A tabular representation


of this entry could also be found in Table 3.1.

23
Table 3.1: The edge table entries for edge a in Figure 3.7
Edge Vertices Faces Left Traverse Right Traverse
Name Start End Left Right Pred Succ Pred Succ
a X Y 1 2 b d e c

3.4 Basic 3D Modeling Concepts

3.4.1 Polygon

Figure 3.8: A cube and its sub-parts

The polygon is comprised of 3 sub-parts below. Figure 3.8 shows an illustration


of a polygon and its sub-parts:

1. A vertex, or sometimes referred to as point, is a single point in 3D space. A


polygon, by requirement, should be comprised of at least 3 vertices.

2. An edge is a line that represents 2 connected vertices.

3. A face is a collection of edges on a single plane. These are sub-polygons


that individually form its own surface.

A 3D model is often composed of multiple polygons that interconnect with


each other as well as share the same vertices and edges. These group of polygons
are called a polygon mesh.

In most 3D modeling applications, the user deals with a primitive polygon in


3D space initially. Primitive polygons are pre-made 3D objects provided by
the software for instant use. Some common types of primitive polygons are cubes,
spheres, cylinders, etc.

24
3.4.2 3D Modeling Transformations and Representations

A modeling transformation is an operation on a polygon or its subparts that


effectively changes its position, size or orientation.

A single modeling transformation could be done using various matrix opera-


tions depending on the type of transformation required. For this purpose, a single
point is represented as a 4x1 matrix (denoted as P); 3 rows for the coordinates
and an extra row to allow the use of a transformation matrix.

 
x
y 
P=
z 
 (3.22)
1

A transformation matrix is a 4x4 matrix that is multiplied to P to achieve


a desired modeling transformation. Equation 3.23 shows the equation for a single
modeling transformation where the resulting point is denoted by P0

P0 = transformation matrix ∗ P (3.23)

The basic 3D modeling transformations are as follows:

Translation

Translation transforms an object’s position. The translation factors (Tx , Ty


and Tz ) specifies the change in position of P in its respective coordinates. This
transformation could be expressed as P0 = T (Tx , Ty , Tx ) ∗ P

 0      
x 1 0 0 Tx x x + Tx
y 0  0 1 0 Ty 
 ∗ y  =  y + Ty 
   
 0 =  (3.24)
z  0 0 1 Tz  z   z + Tz 
1 0 0 0 1 1 1

25
Scaling

Scaling transforms an object’s size. The scaling factors (Sx , Sy and Sz ) specifies
the rate of the scale where the values 0 < S < 1 means scaling down and values s <
1 means scaling up. This transformation could be expressed as P0 = S(Sx , Sy , Sx )∗
P

 0      
x Sx 0 0 0 x x ∗ Sx
 y 0   0 Sy 0
 ∗ y  =  y ∗ Sy 
0    
 0 =  (3.25)
 z   0 0 Sz 0 z   z ∗ Sz 
1 0 0 0 1 1 1

Rotation

Rotation transforms an object’s orientation. The rotation is determined by


an angle θ where a positive value for counterclockwise rotation and negative for
clockwise rotation.

A rotation could be made in 3 various ways:

• Rotation about the x-axis (expressed as P0 = Rx (θ) ∗ P)


 0      
x 1 0 0 0 x x
y 0  0 cosθ −sinθ 0 y  ycosθ − zsinθ
z  0 sinθ cosθ 0 ∗ z  = ysinθ + zcosθ 
 0 =       (3.26)
1 0 0 0 1 1 1

• Rotation about the y-axis (expressed as P0 = Ry (θ) ∗ P)


 0      
x cosθ 0 sinθ 0 x xcosθ + zsinθ
y 0   0 1 0 0 ∗ y  =  y
   
 0 =   (3.27)
z  −sinθ 0 cosθ 0 z  −xsinθ + zcosθ
1 0 0 0 1 1 1

• Rotation about the z-axis (expressed as P0 = Rz (θ) ∗ P)


 0      
x cosθ −sinθ 0 0 x xcosθ − ysinθ
y 0  sinθ cosθ 0 0 y  xsinθ + ycosθ 
 0 =  ∗ =  (3.28)
z   0 0 1 0  z   z 
1 0 0 0 1 1 1

26
Chapter 4

The Point Modeler 2.0 System

This chapter discusses about the target application of this thesis. The objectives
and scope, system architecture and functionalities of the application is discussed
in this chapter.

4.1 System Overview

Point Modeler 2.0 is a 3D modeling mobile application for Android Tablet


PCs. Extending the functionalities of Point: A Gesture Based 3D Modeling tool
(Carlos et al., 2012), this system supports parametric curves, parametric surfaces
and subdivisions. Note that this system only extends the previously mentioned
software in terms of functionality; and that this system is implemented differently.

4.2 System Objectives

Point Modeler 2.0 aims to achieve the following objectives:

• To represent 3D data using the winged-edge data structure (refer to Section


3.3)

• To be able to create, transform and delete vertices, edges and faces

• To implement functionality for parametric curves and surfaces as mentioned


in Section 1.3

27
• To be able to save, load and export previous works/models

4.3 System Scope and Limitations

This system will use the winged-edge data structure (Baumgart, 1972) as de-
scribed in Section 3.3. This data structure is limited in storing data for vertices,
edges and faces only. The system is to display these data as a wireframe model.
Lighting and shading are not covered by the thesis and this system.

The creation, transformation and deletion of vertices, edges and faces is the
focus and main goal of this thesis’ predecessor - Gesture Based 3D Mesh Modeling
(Carlos et al., 2012). These functionalities are reimplemented in this system only
as a formality and should not be confused as one of Point Modeler 2.0 ’s main
functions. Thereof, there will be minimal discussion on these functionalities in
this thesis. The gestures and implementations previously used by Carlos et al. to
achieve these functions may also differ.

The specific curves, surfaces and subdivisions that this system will implement
were discussed in Section 1.3. Supported operations related to this functionality
are creation, deletion, transformation and setting the resolution of the curves,
surfaces or subdivisions. Section 4.5 discusses these operations in detail.

Saving and loading of the models are exclusive to this mobile application only.
Exporting of a model to obj format is also supported; however, the system will not
support any import functionalities of obj’s exported from external 3D modeling
applications such as Blender. Import functionality was excluded because of the
possibility of extra data / complications in the obj file from features that are not
supported by Point Modeler 2.0 . Saved models, however, could be loaded from
one device to another given that both devices are running the same build of Point
Modeler 2.0 .

4.4 Architectural Design

The design discussed in this section conforms to the design of the prototype for
THSST-1. These designs are limited to the modules of Point Modeler 2.0 that
are related to OpenGL, drawing the geometries (basic polygons, curves, surfaces
and subdivisions), and a structure to accommodate the requirements of OpenGL
ES 2.0 (Khronos Group, 2015) along with the different complexities/algorithms

28
of the geometries.

Figure 4.1: An overview of the architectural design of Point Modeler 2.0

The overall system architecture consists of several modules as illustrated in


Figure 4.1. The purpose of these modules are as follows:

1. UI/UX Module is responsible for all modifications to the model depending


on user input.

2. Gradle Module. Gradle is a build system currently used by Android Studio


(refer to Section 4.6). This module is responsible for the direct screen layouts
of the application in xml format as provided by Gradle. For more references
regarding Gradle, refer to (Android Studio, 2016)

3. File Module is responsible for all the file handling process of the applica-
tion. These includes the process for the following system functions: save,
load and export.

4. Data Structure Module is responsible for the data structure of the model.
This is further discussed on Section 4.4.1

5. OpenGL Module is responsible for the abstraction of OpenGL ES 2.0


requirements. This is further discussed on Section 4.4.2.

29
Figure 4.2: A simple class diagram depicting some interactions of the
datastructure package of Point Modeler 2.0

4.4.1 Data Structure Module

The system uses the winged edge data structure to represent the 3D model (Refer
to Section 3.3 for a discussion on this data structure). The class diagram in Figure
4.2 shows Point Modeler 2.0 ’s design for this data structure.

A WingedEdge class is responsible for the collection of all the Edges in the
model. It is initialized with an empty list of edges and is successively added edges
using the addEdge() method. This class is also responsible for extracting all the
MainVertices and Faces of the model through the attributes of the Edges as
they are added.

4.4.2 Abstraction of OpenGL

Point Modeler 2.0 implements a class structure to abstract all necessary OpenGL
calls into a few method calls. The diagram in Figure 4.3 shows these classes and
their main interactions with other classes.

30
Figure 4.3: A simple class diagram depicting some interactions of the drawables
package of Point Modeler 2.0

OpenGL ES 2.0 Draw Requirements

Before the discussion on the class diagram in Figure 4.3, it is first recommended
to know the basic requirements of OpenGL ES 2.0 to draw basic lines and vertices
found in Appendix A.

The drawable Package

The reason for creating a class structure as that of the drawable package is to
abstract all necessary OpenGL calls into only a few method calls. This was
constructed mainly so that there will be no confusion between the geometries
being implemented (such as basic polygons, curves, surfaces and subdivisions)
and the requirements of OpenGL ES 2.0 (refer to Appendix A) to draw these
geometries.

The following main rules were established to be able to make a geometry


’drawable’ by OpenGL ES 2.0:

1. The geometry could return a FloatBuffer of all its vertices including those
that are from interpolation.
2. The geometry could return a FloatBuffer of all its vertices excluding those
that are from interpolation.
3. The geometry specifies, in a ShortBuffer, which vertices in 1.) are inter-
connected

31
An abstract class Drawable was made to make sure that the enumerated rules
above are followed by the geometries. All geometries extend from the Drawable
class and are drawn by OpenGL using their inherited draw() function.

The class Drawer was made to encapsulate all the requirements and necessary
steps of OpenGL ES 2.0 to draw; this includes the shader codes and its compila-
tion, OpenGL ES program creation, and attributes binding. There is one instance
of Drawer for every Drawable. Whenever a Drawable needs to be drawn (such
that the Drawable’s draw() method was invoked), its Drawer gets all the nec-
essary Buffers from the Drawable and binds these Buffers to the OpenGL ES
program to be processed by the graphics card.

4.5 System Functions

The functionalities to be implemented in this system could be classified into the


following:

4.5.1 Main Functions

Main functions are those that are directly related to the topic of this thesis. This
is inclusive of all operations on curves, surfaces and subdivisions only.

Curves

• Creation of a curve given already existing control points or inter-connected


vertices in the model. Note that different kinds of curve will require different
number of control points/vertices.

• Deletion of a whole curve. Deletion of a single or a part of the curve’s


control points are not supported.

• Translation, scaling and rotation of selected control point/s of a curve.

• Curve resolution or how smooth a curve is.

Surfaces

32
• Addition of pre-defined Bezier and NURBS surfaces/patches to the model.

• Deletion of a whole surface/patch. Deletion of a single or a part of the


surface/patch’s control points are not supported.

• Translation, scaling and rotation of selected control point/s of a surface/-


patch.

Subdivision Surfaces

• Subdivision of a selected closed patch or a selected closed mesh, both with-


out holes, using Catmull and Clark (1978)’s subdivision surfaces algorithm
(Refer to Section 3.2.1)

• Deletion of a whole subdivided mesh. Deletion of a part of the subdivided


mesh is not supported.

• Translation, scaling and rotation of a subdivided mesh’s/patch’s original


vertices.

• Subdivision iterations

4.5.2 Miscellaneous Functions

Miscellaneous functions are those that are not explicitly related to the topic of
this thesis, however, are necessary for a proper or usable 3D modeling mobile
application.

Creation Tools
These tools allow the creation of vertices, edges, faces or predefined meshes.

Basic Transformation Tools


This includes translation, rotation and scaling of vertices, edges or faces.

Picking/Selection Tools
The user has the option to select the following:

• Vertices

33
• Faces

• Curves

• Surfaces

• Subdivisions

Multiple selection are supported by the system for vertices and faces only.

Camera/Viewing Tools
The system will support the following camera/viewing operations:

• Rotation of the camera the x and y axes.

• Zoom in or zoom out

Saving/Loading Tools
This functionality allows the user to save and load a model. Additionally, the
user is also allowed to duplicate a saved model. Limitations on this functionality
could be found in Section 4.3.

4.6 Physical Environment and Resources

Software The system is designed specifically for Android Tablet PCs. Develop-
ment tools used are Android Studio - the official IDE for Android Development -
and OpenGL ES 2.0 (note that OpenGL ES 2.0 already comes bundled with An-
droid Studio and is readily available for use with the IDE). Miscellaneous software
used in designing or modifying the application assets are Adobe Photoshop CS6
and Adobe Illustrator CS6. Github will also be used in the development phase
for a timestamp of when and how long the functionalities were being developed
through the commits made.

Hardware The hardware required to run the application is one that can support
OpenGL ES 2.0. The PC used for development is an Asus Transformer Book
T300LA. The tablet to be used for testing the application is a 10.5” Samsung
Galaxy Tab S.

34
Appendix A

OpenGL ES 2.0 Draw


Requirements

The requirements identified in this section are exclusive for OpenGL ES 2.0 and
will differ from its previous version, OpenGL ES 1.0.

Vertex Shader and Fragment Shader


Since OpenGL ES 2.0, developers need to specify the data that the graphics
processor will handle. This extra step, which is not available for the previous
version of OpenGL ES, provides programmers with a full access to the underlying
hardware, and consequently enhanced graphics rendering, through the use of a
user-defined program called shaders.

Point Modeller 2.0 only defines two shaders (or ”shader stage” as it is formally
referred to, and from now on will be referred to as such): the Vertex Shader and
the Fragment Shader. The code for these stages, which are in OpenGL Shading
Language (GLSL), specify the data, its datatype, and what to do with or opera-
tions on the data. Since Point Modeller 2.0 only defines 2 of these stages, only
these will be further discussed.

An example of a Vertex Shader code is showed in Listing A.1. This stage


handles processing for individual vertices. For this example, the code specifies
that the graphics card will be processing the following data:

• A 4x4 matrix (mat4), uMVPMatrix, that will have the same values for each
vertex (uniform)

35
• A vector consisting of 4 values (vec4), aColor, that will have different values
per vertex (attribute)

• A vector consisting of 4 values (vec4), vPosition, that will have different


values per vertex (attribute)

• A vector consisting of 4 values (vec4), vColor, that will be passed on to the


Fragment Shader (varying)

Listing A.1: The Vertex Shader Code of Point Modeller 2.0


1 uniform mat4 uMVPMatrix ;
2 attribute vec4 aColor ;
3 attribute vec4 v P o s i t i o n ;
4
5 varying vec4 vColor ;
6
7 void main ( ) {
8 vColor = aColor ; /∗ Pass t h e v a l u e o f aColor t o
9 t h e Fragment Shader as v C o l o r ∗/
10
11 gl PointSize = 3 0 . 0 ; /∗ S e t t h e p o i n t s i z e per
12 v e r t e x ∗/
13
14 gl Position = uMVPMatrix ∗ v P o s i t i o n ; /∗ S e t t h e
15 p o s i t i o n o f t h e v e r t e x ∗/
16 }

The next and last stage that Point Modeler 2.0 defines is the Fragment Shader.
This stage handles the processing for the individual fragments of a model. Listing
A.2 shows an example of a Fragment Shader code.
Listing A.2: The Fragment Shader Code of Point Modeller 2.0
1 precision mediump f l o a t ;
2 varying vec4 vColor ; /∗ Gets t h e i n t e r p o l a t e d v a l u e o f
3 v C o l o r from t h e V e r t e x Shader Code ∗/
4
5 void main ( ) {
6 gl FragColor = vColor ; /∗ S e t s t h e f r a g m e n t
7 c o l o r ∗/
8 }

36
In openGL ES 2.0 for Java, these shader codes are most commonly specified
in a String variable. Point Modeler 2.0 defines these shaders as a String vari-
able, vertexShaderCode and fragmentShaderCode, of the Drawer class as seen
in Figure 4.3. These variables are then compiled as can be seen in Listing A.3 for
later use.
Listing A.3: A code snippet for shader code compilation in Java
1 // Create an empty s h a d e r code s p e c i f y i n g t h e t y p e o f
2 // s h a d e r as parameter
3 int v e r t e x S h a d e r = GLES20 . g l C r e a t e S h a d e r (
4 GLES20 .GL VERTEX SHADER ) ;
5 int fragmentShader = GLES20 . g l C r e a t e S h a d e r (
6 GLES20 .GL FRAGMENT SHADER) ;
7
8 // Attach t h e s h a d e r code s t o r e d i n v e r t e x S h a d e r C o d e and
9 // fragmentShaderCode t o t h e r e s p e c t i v e c r e a t e d s h a d e r s
10 GLES20 . g l S h a d e r S o u r c e ( v e r t e x S h a d e r , vertexShaderCode ) ;
11 GLES20 . g l S h a d e r S o u r c e ( fragmentShader , fragmentShaderCode ) ;
12
13 // Compile t h e s h a d e r s
14 GLES20 . glCompileShader ( v e r t e x S h a d e r ) ;
15 GLES20 . glCompileShader ( fragmentShader ) ;

OpenGL ES Program

The shader codes are processed by the system through an OpenGL ES program.
Similar to shader compilation previously discussed, OpenGL ES 2.0 also already
provides a functionality to be able to create an OpenGL ES program, attach the
specified shader codes to the said program, and link (or create an executable of)
the program to the system. These functionalities/process is described in Listing
A.4.
Listing A.4: A code snippet for OpenGL ES Program creation in Java
1 // Create empty OpenGL ES Program
2 mProgram = GLES20 . glCreateProgram ( ) ;
3
4 // Add t h e v e r t e x s h a d e r t o program
5 GLES20 . g l A t t a c h S h a d e r ( mProgram , v e r t e x S h a d e r ) ;
6
7 // Add t h e f r a g m e n t s h a d e r t o program

37
8 GLES20 . g l A t t a c h S h a d e r ( mProgram , fragmentShader ) ;
9
10 // C r e a t e s OpenGL ES program e x e c u t a b l e s
11 GLES20 . glLinkProgram ( mProgram ) ;

Attribute Buffers
After specifying and compiling the shader codes, creation of the OpenGL ES
program and attaching the shader codes to the program, all that is left for OpenGL
ES to be able to draw is to give values to the attributes specified in the shader
code. This is done in Java by binding the shader code attributes to a Buffer.
Listing A.5 shows a code snippet of binding the vPosition attribute of the Verted
Shader code to a Buffer named vertexBuffer.
Listing A.5: A code snippet for binding shader code attributes to Buffers in Java
1 // Get h a n d l e t o v e r t e x s h a d e r ’ s v P o s i t i o n member
2 mPositionHandle = GLES20 . g l G e t A t t r i b L o c a t i o n (
3 mProgram , // The program b e i n g used
4 ” vPosition ” ) ; // The name o f t h e a t t r i b u t e
5
6 GLES20 . g l V e r t e x A t t r i b P o i n t e r (
7 mPositionHandle ,
8 3, // S i z e (3 c o o r d i n a t e v a l u e s per v e r t e x )
9 GLES20 . GL FLOAT, // Datatype
10 false , // I s v a l u e s n o r m a l i z e d ?
11 3 ∗ 4, // S t r i d e (3 c o o r d i n a t e v a l u e s ∗ 4 b y t e s
12 // per v e r t e x )
13 vertexBuffer // B u f f e r
14 ) ;

38
References

3D Creationist. (2016). 3d creationist. Retrieved March 19, 2016, from http://


3dcreationist.com/
Android Studio. (2016). Android studio - configure your build. Retrieved Novem-
ber 4, 2016, from https://developer.android.com/studio/build/index
.html
ASCON. (2016). Subdivformer. Retrieved March 19, 2016, from
https://play.google.com/store/apps/details?id=com.ascon
.subdivformer&hl=en
Baumgart, B. G. (1972). Winged edge polyhedron representation. (Tech. Rep.).
Stanford, CA, USA.
Blender Foundation. (2016). Blender. Retrieved March 3, 2016, from https://
www.blender.org/
Carlos, R., Jr., C. D., Sanchez, A., & Tolentino, K. (2012). Gesture based 3d
mesh modeling [Undergraduate Thesis].
Catmull, E., & Clark, J. (1978). Recursively generated b-spline surfaces on
arbitrary topological meshes. Computer-Aided Design, 10 (6), 350 - 355.
Retrieved from http://www.sciencedirect.com/science/article/pii/
0010448578901100 doi: http://dx.doi.org/10.1016/0010-4485(78)90110-0
Farin, G. E. (1996). Curves and surfaces for computer-aided geometric design: A
practical code (4th ed.). Orlando, FL, USA: Academic Press, Inc.
Khronos Group. (2015). The standard for embedded accelerated 3d graphics.
Retrieved October 4, 2015, from https://www.khronos.org/opengles/
Mehta, P. (2013). Learn opengl es. Apress. doi: 10.1007/978-1-4302-5054-8
Olsen, L., Samavati, F. F., Sousa, M. C., & Jorge, J. A. (2009). Sketch-
based modeling: A survey. Computers & Graphics, 33 (1), 85–103.
Retrieved from http://www.sciencedirect.com/science/article/pii/
S0097849308001295 doi: http://dx.doi.org/10.1016/j.cag.2008.09.013
Quinn, J. (2016). Qubism 3d modeling. Retrieved March 19,
2016, from https://play.google.com/store/apps/details?id=jquinn
.qubism.android&hl=en

39

Das könnte Ihnen auch gefallen