[ Prev | Index | Next ]
Japanese English
Now Loading...
Download
Please download on PC (not smartphone) and extract the ZIP file. Then double-click VCSSL.bat (batch file) to execute for Microsoft® Windows®, or execute VCSSL.jar (JAR file) on the command line for Linux® and other OSes.
For details, see How to Use.
You are free to use and modify this program and material, even for educational or commercial use. » Details

Creating a Model from a Vertex Array (Quadrangle Grid Mesh Format)

This program is a VCSSL sample that creates a 3D model from a vertex array.

When creating a custom-shaped model in VCSSL, the most basic method is to define each polygon individually and combine them to form the model. However, if the polygons are arranged in a regular pattern, it's also possible to directly generate a model from a float array that stores vertex coordinates.

That said, there are several different formats and orders in which to store vertex coordinates in the array. In this program, we'll use the Quadrangle Grid Mesh format (QUADRANGLE_GRID), which is especially useful for visualization in simulations and similar applications.

- Table of Contents -

Sponsored Link


How to Use

Download and Extract

At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.

If you are using Windows, right-click the ZIP file and choose "Properties" from the menu, and enable "Unblock" checkbox at the right-bottom (in the line of "Security") of the properties-window. Otherwise, when you extract the ZIP file or when you execute the software, security warning messages may pop up and the extraction/execution may fail.

Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.

» If the extraction of the downloaded ZIP file is stopped with security warning messages...

Execute this Program

Next, open the extracted folder and execute this VCSSL program.

For Windows

Double-click the following batch file to execute:

VCSSL__Double_Click_This_to_Execute.bat

For Linux, etc.

Execute "VCSSL.jar" on the command-line terminal as follows:

cd <extracted_folder>
java -jar VCSSL.jar

» If the error message about non-availability of "java" command is output...

Operations After Launch

When you run the program, a window will open, displaying a 3D surface.

You can control the view using the mouse as follows:

  • Left drag: Rotate the viewpoint
  • Right drag: Move the viewpoint
  • Scroll wheel: Zoom in/out

Topic Overview

What Is the Quadrangle Grid Mesh Format?

When a model consists of a collection of quadrangles, the most basic format for the vertex array is the Quadrangle List (QUADRANGLE_LIST), where each quadrangle independently specifies four vertices.

However, if the quadrangles are arranged in a grid and form a surface, neighboring quadrangles share their vertices. In such cases, specifying all four vertices for every single quadrangle becomes tedious.

Instead, it's much more convenient to generate the model from a coordinate array that includes indices for both the vertical and horizontal directions of the grid. This is what we call the Quadrangle Grid Mesh (QUADRANGLE_GRID) format.

Format of Coordinate Arrays in the Quadrangle Grid Mesh Format
Structure of Coordinate Arrays in the Quadrangle Grid Mesh Format

Black lines represent the edges of quadrangles, and the blue dots are grid points. A surface composed of such quadrangles can be fully specified using only the coordinates of the grid points.

In the Quadrangle Grid Mesh (QUADRANGLE_GRID) format, the coordinate array stores vertex positions using a 3D "float" array structured as: "[ Y Grid Index ][ X Grid Index ][ X/Y/Z (0/1/2)]"

Assuming the grid lies in the X-Y plane (though Y-Z or Z-X also work), this array structure holds the position of each grid point.

How to Create a Vertex Coordinate Array

As shown in the diagram above, coordinate arrays in this format are structured as:

[ Y Grid Index ][ X Grid Index ][ X/Y/Z (0/1/2) ]

The first and second dimensions represent the Y and X indices of the grid. See the diagram for specific index values.

Note: Be careful that the format is [Y Grid Index][X Grid Index], not [X Grid Index][Y Grid Index]. This reversal of indices also applies when working with grids in the Y-Z or Z-X directions.

If you use [X Grid Index][Y Grid Index], the direction of face culling (which determines front and back sides of polygons) will be flipped. This only matters when culling is enabled; if culling is disabled, the result remains visually the same.

The third dimension represents the coordinate axes for each point: 0 for X, 1 for Y, and 2 for Z.

Also, the actual X coordinate values of points sharing the same X grid index (first dimension) don't have to be equal -- the same applies to Y. This allows for the expression of distorted or irregular grids as well.

Code

Full Code

The full code of this program is as follows:

In the next section, we'll explain each part of the code in detail.

Header Section

At the top of the program, we import the standard libraries for mathematical functions (Math), 3D graphics (Graphics3D), and the 3DCG framework (graphics3d.Graphics3DFramework):

Declaring Global Variables

Next, we declare some global variables. Here, we define the number of grid points (divisions) in the X and Y directions.

The "const" keyword locks the value so it cannot be changed, effectively making it a constant. This helps prevent bugs caused by accidentally modifying values that are meant to remain unchanged.

Implementing the onStart(...) Function

Next, we implement the onStart(...) function. This function is automatically called once when the program starts, and is where we perform initialization tasks such as configuring the screen and generating or mounting 3D models.

Let's go through it step by step. First, we declare the array that will store the vertex coordinates. Note that the dimensions are ordered as [ Y_N ][ X_N ]:

Next, we populate this array with coordinate values:

For the X and Y coordinates, we use values that create an orthogonal grid (although distorted grids are also possible).

The Z coordinate is calculated using sine functions of X and Y to create a wavy surface.

Now comes the main part: creating the model from the vertex array, setting its color, and mounting it. First, we create the model:

newModel(...) is a function in the Graphics3D library used to create 3D models.

The argument QUADRANGLE_GRID is a constant defined in the Graphics3D library and acts as a keyword indicating the quadrangle grid format. Following that, we pass in the "vertex" array, which will be interpreted using this format.

The newModel(...) function creates a model from the provided vertex array and returns a unique model ID assigned to it. In this example, we store it in a variable named "model", which is of type int. The model ID is necessary for placing or manipulating the model.

Next, we use the setModelColor() function, also from the Graphics3D library, to set the model's color:

The first argument is the ID of the model whose color you want to change.

The next three arguments specify the red, green, and blue color components as integers in the range 0-255. These are mixed additively to determine the final color. The last argument is the alpha value (also 0-255), which defines the transparency: 0 is fully transparent, and 255 is fully opaque.

Finally, we mount the model:

mountModel() is another function in the Graphics3D library, used to place models. The first argument is the ID of the model to mount.

The second argument is the ID of the 3D renderer (the 3D drawing engine), which the framework automatically provides. This renderer ID is passed to the onStart(...) function as the "renderer" argument, so we can just pass it directly here.

Note: The mountModel() function also allows an optional third argument to specify the coordinate system in which to place the model. If omitted, as in this example, the model is placed in world coordinates. We won't go into the details of world coordinates here, but you can think of it as the global stage on which all models are placed.

License

This VCSSL/Vnano code (files with the ".vcssl" or ".vnano" extensions) is released under the CC0 license, effectively placing it in the public domain. If any sample code in C, C++, or Java is included in this article, it is also released under the same terms. You are free to use, modify, or repurpose it as you wish.

* The distribution folder also includes the VCSSL runtime environment, so you can run the program immediately after downloading. The license for the runtime is included in the gLicenseh folder.
(In short, it can be used freely for both commercial and non-commercial purposes, but the developers take no responsibility for any consequences arising from its use.) For details on the files and licenses included in the distribution folder, please refer to "ReadMe.txt".

* The Vnano runtime environment is also available as open-source, so you can embed it in other software if needed. For more information, see here.



Sponsored Link



Japanese English
[ Prev | Index | Next ]
Simple Tool for Viewing and Converting Between RGB Values and Color Codes

Display and Convert RGB Values and Color Codes on a GUI Tool
A Simple Tool for Making Specific Colors Transparent (Batch Processing Version)

Batch-Convert a Specific Color to Transparency in All PNG Files in a Folder
A Simple Tool for Making Specific Colors Transparent

Convert a Specific Color to Transparency in PNG Image Files
Simple Tool for Animating Sequential Images

A lightweight tool developed with VCSSL that allows you to play back sequential image files as an animation without converting them into a video file.
Vertex Array-Based Model Deformation Animation

How to Deform 3D Surface Models Using a Grid-Based Vertex Array
Creating a Model from a Vertex Array (Quadrangle Grid Mesh Format)

How to Create 3D Surface Models from a Grid-Based Vertex Array
Index
[ Prev | Index | Next ]
Simple Tool for Viewing and Converting Between RGB Values and Color Codes

Display and Convert RGB Values and Color Codes on a GUI Tool
A Simple Tool for Making Specific Colors Transparent (Batch Processing Version)

Batch-Convert a Specific Color to Transparency in All PNG Files in a Folder
A Simple Tool for Making Specific Colors Transparent

Convert a Specific Color to Transparency in PNG Image Files
Simple Tool for Animating Sequential Images

A lightweight tool developed with VCSSL that allows you to play back sequential image files as an animation without converting them into a video file.
Vertex Array-Based Model Deformation Animation

How to Deform 3D Surface Models Using a Grid-Based Vertex Array
Creating a Model from a Vertex Array (Quadrangle Grid Mesh Format)

How to Create 3D Surface Models from a Grid-Based Vertex Array
News From RINEARN
* VCSSL is developed by RINEARN.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!

Inside the Repetitive Execution Speedup Impremented in Vnano Ver.1.1
2024-01-17 - Delves into the update in Vnano 1.1 from a developer's viewpoint, providing detailed insights into the specific improvements made to the internal structure of the script engine.

Scripting Engine Vnano Ver.1.1 Released: Dramatic Speed Improvement for Repetitive Executions of the Same Content
2023-12-22 - Released the Vnano script engine Ver.1.1. In this version, we've made significant enhancements in processing speed by reducing the overhead of handling requests. Explains the details.