简体   繁体   English

为Flash AS3和Away3D中的对象创建自定义类

[英]Making a custom class for objects in Flash AS3 & Away3D

I'm going to make a tile-based 3D RPG game in Flash AS3 with Away3D API. 我将使用Away3D API在Flash AS3中制作基于图块的3D RPG游戏。

my problem is that i dont really understand the away3d api so far.. 我的问题是,到目前为止,我还不太了解away3d api。

I want to make a "blocks" class. 我想做一个“积木”课程。 if i load the tile-map-data, i want to make something like this: 如果我加载tile-map-data,我想做这样的事情:

viewport.addchild( tileArray[ layer ][ x ][ y ] );

so this would be in a loop. 所以这将是一个循环。

so far so good, but this would have to be a 3dObject. 到目前为止,一切都很好,但这必须是3dObject。

to fill that array with that 3dObject i want to make something like this. 用那个3dObject填充那个数组,我想做这样的事情。

tileArray[ layer ][ x ][ y ] = myBlocksClass.getBlock( "grassCube" );

so the getBlock functon in myBlocksClass sould return me a 3dObject. 因此,myBlocksClass中的getBlock函数将向我返回3dObject。

<edit>

those blocks should be some sort of blocks like in minecraft ( grassCube, dirtCube,... ) so i want to load multiple instances of one block in a map 这些块应该是类似于我的世界中的某种块(grassCube,dirtyCube等),因此我想在地图中加载一个块的多个实例

</edit>

how can i do this ? 我怎样才能做到这一点 ? does anyone can give me any idea or maybe a reference ? 有谁能给我任何想法或参考?

and YES i've allready looked in all awaylable resources / documentarys / examples, but i could't figute it out anyway. 是的,我已经准备好查阅所有可访问的资源/纪录片/示例,但无论如何我都无法弄清楚。

UPDATE: 更新:

the question is more to code. 问题更多是代码。 i know the theory, but actionscript3 for game dev is nearly new to me. 我知道理论,但是游戏开发人员的actionscript3对我来说几乎是新手。

how to structure the class for the "blocks" ? 如何为“块”构造类?

Most of 3D applications actually are tile based. 实际上,大多数3D应用程序都是基于图块的。 For example popular terrain implementation is set of chunks with hight resolution mash for close range and low for far. 例如,流行的地形实现是一组块,其中高分辨率的mash代表近距离,低分辨率的mash代表远距离。 Those chunks(and every objects in scene) are organised in scene graph. 这些块(以及场景中的每个对象)都组织在场景图中。 normally its octree . 通常是八叉树 八度地形

Allso there is frustum culling 这样就出现了平截头截体

And engine renders only those nodes that are partially(or totally) inside View pyramid. 并且引擎仅渲染部分(或全部)位于View金字塔内部的节点。

Here is Away3D realisation 这是Away3D的实现

Case-specific optimisation allso very important but very tricky. 特定于案例的优化非常重要,但非常棘手。 For example terrain mesh vertices order and chunk size optimised for GPU chace hits and could be GPU specific (build for specific client) and in the same time related to amount of textures and shading (you do not want to swap materials if you do not need so it good idea to render chunks with same material one by one then swap material) Or if you have let's say 1000 textured cubes you need only one model that will be drawn 1000 times with different materials. 例如,地形网格顶点的顺序和块大小已针对GPU最佳匹配进行了优化,并且可能是GPU特定的(针对特定客户端构建的),并且同时与纹理和阴影的数量有关(如果不需要,您不希望交换材质因此,最好先将具有相同材质的块依次渲染,然后再交换材质。)或者,假设有1000个纹理立方体,则只需一个模型即可使用不同材质绘制1000次。 It's good for GPU memory but its like 10000 draw calls and could hurt your performance badly. 它对GPU内存很有用,但它像10000次绘制调用一样,可能会严重损害您的性能。 So you may want to weld them to bigger objects that fits nicely in octree nodes and have combined textures. 因此,您可能希望将它们焊接到恰好适合八叉树节点并具有组合纹理的较大对象。 But you obviously want to discard those cubes that are underground and can't be seen. 但是您显然想要丢弃那些地下且看不见的立方体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM