用场景来分析的话,一个场景是.stf文件(Speed Tree Forest).该文件描述了每棵树的相关属性。而一棵树是通过一个.spt(Speed Tree)文件来描述的.用文本编辑器打开,就能看到里面记录了该树的所有信息。而该插件为此开发了配套了树木编辑器材。使用该编辑器,打开.spt文件之后,就可以对该树进行浏览以及编辑。
.spt 文件
What is .spt and how to open .spt file
.spt, namely SpeedTree Data file, is a Tree Data file format created by SpeedTreeCAD. SPT files belong to a kind of 3D image file, thus it could be opened by other 3D image program.
SPT files are used for tree geometry construction, LOD data implementation, wind animation and cloning.
open spt file on Windows:
IDV SpeedTreeCAD
Autodesk 3ds max with SpeedTreeMAX plugin
Autodesk Maya with SpeedTreeMAYA plugin
.spt
文件类型1:SpeedTree Tree Data File
文件说明:
Contains procedural tree data used by SpeedTreeCAD, a tree modeling program; includes information required to construct the tree geometry, as well as data for LOD implementation, wind animation, and cloning.
SPT files can also be read by other 3D modeling programs that have the SpeedTreeMAX or SpeedTreeMAYA plugins installed.
打开.spt文件
Mac OS
Windows
IDV SpeedTreeCAD
Autodesk 3ds max with SpeedTreeMAX plugin
Autodesk Maya with SpeedTreeMAYA plugin
Linux
其它内容
.spt
文件类型2:TM File Packer Compressed Archive
文件说明:
Compressed file or group of files created with TM File Packer, a file compression program developed by TMAgency; can be used to split, compress, and decompress files.
NOTE:
TMAgency is a pay-per-download sponsor; TM File Packer is an adware program, so using the software is not recommended.
打开.spt文件
Mac OS
Windows
TMAgency TM File Packer
Linux
.spt
文件类型3:ESPL Programming File
文件说明:
Source code written in the ESPL language; used for creating programs with scientific or research applications
打开.spt文件
Mac OS
Windows
Ensign ESPL Editor
Linux
Load Functions
The CSpeedTreeRT class provides two overloaded LoadTree() functions; one that takes a filename and another that takes a pointer to a memory block containing the SPT definition. Example code for reading an SPT file using a filename is below:
// allocate an object
CSpeedTreeRT* pTree = new CSpeedTreeRT;
// load an SPT file using a filename
if (pTree->LoadTree(pFilename))
{
// plenty to do here, but we're just demonstrating a load
}
else
fprintf(stderr, "LoadTree() failed: %s/n", CSpeedTreeRT::GetCurrentError( ));
The more commonly used method in game titles is the LoadTree() that takes a memory pointer. The example below reads a file into a buffer and then passes that buffer in (this is how the first LoadTree() function works):
// assume a few external objects
extern const char* pFilename;
extern CSpeedTreeRT* pTree;
bool bSuccess = false;
FILE* pFile = fopen(pFilename, "rb");
if (pFile)
{
// how many bytes in the file to be read?
fseek(pFile, 0L, SEEK_END);
int nNumBytes = ftell(pFile);
// go back to the start of the file
int nErrorCode = fseek(pFile, 0, SEEK_SET);
// proceed if the file isn't empty and no errors occurred
if (nNumBytes > 0 && nErrorCode >= 0)
{
// read all of the file into memory, then pass into other Parse() function
pMemory = new unsigned char[nNumBytes];
int nBytesRead = int(fread(pMemory, 1, nNumBytes, pFile));
if (nBytesRead == nNumBytes)
{
bSuccess = pTree->LoadTree(pMemory, nNumBytes);
delete[] pMemory;
}
else
throw(runtime_error(IdvFormatString("only read %d of %d from %s [%s]", nBytesRead, nNumBytes, pFilename, strerror(errno)).c_str( )));
fclose(pFile);
}
else
throw(runtime_error(IdvFormatString("file seek failed on '%s' [%s]", pFilename, strerror(errno)).c_str( )));
}
else
throw(runtime_error(IdvFormatString("failed to load file '%s' [%s]", pFilename, strerror(errno)).c_str( )));
Geometry Generation
SPT files do not store actual geometry, so loading them into the class is only the first step. Another function, Compute(), must be called that will generate the geometry from the procedural definition. The code below builds on the first LoadTree() sample and shows the basics of how this is accomplished.
// allocate an object
CSpeedTreeRT* pTree = new CSpeedTreeRT;
// load an SPT file
if (pTree->LoadTree(pFilename))
{
// todo: setup wind, lighting configuration
// generate geometry from procedural definition
if (pTree->Compute( ))
{
// to do: create vertex and index buffers, load textures
// to do: memory no longer needed
}
else
{
fprintf(stderr, "Compute() failed: %s/n", CSpeedTreeRT::GetCurrentError( ));
}
}
else
fprintf(stderr, "LoadTree() failed: %s/n", CSpeedTreeRT::GetCurrentError( ));
Save Function
CSpeedTreeRT also supports the ability to write an SPT that describes that model currently stored in the class. This function is largely used by world editors and tools in the SpeedTree product family. It is not expected that this functionality will be needed in a typical SpeedTree-using application.
For more information, see the SaveTree() help page in the reference manual.
Load & Compute Times
As measured from the Tree Model Library v2.2 (commonly paired with the SpeedTreeRT 1.8 release), the SpeedTreeRT load and compute times were*:
Average load time: 5.35 ms
Median load time: 5.38 ms
Average compute time: 19.24 ms
Median compute time: 8.49 ms
* Measurements were taken on a 3.2 GHz P4 Windows PC with 1GB of RAM.
The bulk of the compute CPU load, as measured using a CPU profiler, is from the leaf cloud generation routine. This routine spends time ensuring that when a new leaf is created that it is not too close to the other leaves in the cloud.
Controlling the Load Time
Given that the leaf cloud generation time dominates the compute time for an SPT model, there is a new optimizing tool in SpeedTreeCAD 4.0 to help manage this. From the CAD documentation:
Optimize Leaf Generation Frequency
This option will lower the leaf generation frequency to a value where only a certain percentage of leaves (configurable by the user in the next option, typically set to 90%) remain. Because the leaf placement algorithm will outright reject many leaves, many trees are left with leaf generation frequencies that are artificially high. These high frequencies often result in longer than necessary initialization times (which affect both real-time application load times and SpeedTreeCAD's interactive computing). Select this option to automatically lower the leaf generation frequency to a value suitable for the leaf count on the current tree. Selecting this option automatically enables initialization time reporting in the tree window (normally accessed via the View pulldown menu).
Tree Model Library 4.0
The 4.0 model library will be the first library released where this tool has been used to optimize the leaf cloud generation time without sacrificing the aesthetic of the tree. However, CAD's optimization tool will work just fine with trees from older libraries.
.stf 文件
The SpeedTree Forest (STF) file format facilitates the incorporation of SpeedTree tree models into applications that utilize the SpeedTreeRT library. The STF exporters in both 3ds max and Maya allow developers to position trees, choose appropriate seed values, place instances, and create forests inside of the respective applications. The exporters generate ASCII files containing the name of each unique tree, its seed, its size, and the position, rotation, and scale of all instances of that tree in the scene. Click on the links below to learn more about the STF format and how to use it in your application.
“.stf” files are ASCII text files that contain a list of each unique tree in the 3ds max scene. The data stored for each tree are, in order, the ".spt" filename, seed, and the number of instances of the tree. The position, rotation (in radians), and scale of each instance follows. The following BNF describes the structure of an “.stf” file.
<STF File> ::= {<Tree entry>}
<Tree entry> ::= <Filename> <Seed> <Size> <Instances>
<Seed> ::= <unsigned int>
<Size> :: = <float> <float>
<Instances> ::= <unsigned int> {<Placement>}
<Filename> ::= {<char>}
<Placement> ::= <float> <float> <float> <float> <float> // x, y, z, rotation (radians), & scale
The listing below demonstrates a sample ".stf" file.
Agarwood.spt
301409
60 10
1
-40.4579 33.0828 0 0.773471 1.25
BostonFern_Cluster.spt
522315
60 10
3
32.5914 112.758 0 0 1
32.5914 58.273 0 0 1
32.5914 16.9102 0 0 1
WeepingWillow.spt
301409
60 10
1
-40.1446 -46.1798 0 0 1
WhitePine.spt
285408
60 10
3
29.6862 -16.0832 0 0 1
29.6862 -35.3341 0 0 1
29.6862 -54.0787 0 -0.749767 1.571
The following list describes the typical workflow when using the SpeedTree Forest Exporter. An example of ".stf" file parsing can be found in the samples provided with the SDK.
Create a 3ds max or Maya scene that includes SpeedTree objects. This scene may include both single trees and forests. Please refer to the SpeedTreeMAX or SpeedTreeMAYA documentation for information on how to use SpeedTree within those applications.
In 3ds max, select File->Export in 3ds max to bring up the export dialog. Select “SpeedTree Forest (*.STF)” in the Save as type combo box. Choose a filename and select Save.
In Maya, run the STF export MEL script and then type exportSTFFile at the command prompt.
Create a composite leaf map from each of the SPT files used in the scene with SpeedTreeCAD.
Load the composite leaf map as you would any texture map in your application.
Parse the “.stf” file and use the information to add trees to your scene (see reference application in the SpeedTreeRT distribution for more on STF file parsing).