关于speedtree的spt文件和stf文件

1649 篇文章 11 订阅
1623 篇文章 22 订阅

用场景来分析的话,一个场景是.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).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你还在为写文件而发愁吗? 你还在不断的重复前人走过的路么? 你还在为不断变更的写文件的需求而苦恼么? 你还在为你的写文件效率不高而奔波于贴吧之间么? 随着C、C++的发展,使用的人越来越多,不管是linux还是windows或者是其他的平台。在使用过程中我们发现这门语言对于写文件的操作是在不方便,原始的标准库中只给定了基本的写文件操作,对于多数应用中需要将结构体或者类中的成员写入到文件中,没有一个好的办法,除了用fpintf外。但这种老土而效率低下的方式,严重降低了开发者的产出,同时还会出现不必要的错误,后期代码的维护也是更是头痛的事。这里向大家推荐一个通用的结构体写文件的库----STF (struct to file),这个库的主要功能就是将接头体转换到文件中。这个过程不需要自己写代码对文件的操作。只需要调用函数接口,剩下的就是配置写文件的格式即可和编译stf运行库。所有的工作就只需要三步。输出数据可以是结构体中的任意字段,任意顺序,甚至可以对部分字段进行算术运算。同时可以将同一个结构体同时输出到多个文件中,更可以将不同类的共有基类输出到同一个文件中。在性能方面stf考虑到了现在大型服务器并发的性。将写磁盘的速度达到最大化。只要磁盘硬件能更上,完全不用担心写文件的性能更不上的问题。stf库同时也提供了丰富的日志统计,对收到的数据量,每个文件的数据量做了全方位的统计。更强大的该库对内存的使用十分低,如果出现有内存过高,可以通过详细的日志信息让你掌握,内存到底用到哪里去了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值