Hi Michael,
In order to optimize textures of town, i use a custom clipping script.
I figured out that away3d do clipping but when a lot of objects are
"added" to the scene, performance goes down.
So I put a script that remove object when they are far or behind the
camera.
I used a lot of SrpiteRenderSession and movePivot to correct the Z-
sorting.
For texture i put in array 3 kind of bitmap for each texture: High/
Medium/Low. The textures switches depends on the distance from the
camera.
And the 100 first frame calculate the average fps of the project and
switch automatically this parameters:
-Max Distance Clippin
-Medium Texture Distance
-High Texture Distance
-Quality of flash player
-Resolution of the frustum clipping thing.
It's a sample of tick :
public function update(cam:Camera3D,Conf:Object):void{
if (!reset){
//Distance processing
//DISTANCE
var c:Number3D = new
Number3D(cam.x,cam.y,cam.z);
//ANGLE
var mc = cam.viewMatrix;
for (var o in Objects) {
//TRANFORM CENTER TO THE CAMERA
var ct:Number3D = new Number3D();
ct.clone(Objects[o].extra.center);
ct.transform(ct,mc);
if
(c.distance(Objects[o].extra.center)<Conf.Clipping.MaxDist&&
(ct.z>-200)){
if (!Objects[o].extra.set){
if
(Objects[o].extra.container){
Objects[o].extra.container.addChild(Objects[o]);
}else
addChild(Objects[o]);
Objects[o].extra.set =
true;
}
if (!Objects[o].extra.noswitch){
//Quality selection
if
(c.distance(Objects[o].extra.center)<Conf.Clipping.High){var
Q = 2;
}else{
if
(c.distance(Objects[o].extra.center)<Conf.Clipping.Medium)
var Q = 1;
else Q = 0;
}
if
((Objects[o].extra.Quality!=Q||Objects[o].extra.Blur)){
//Texture
loading and switching
var
faceMat:BitmapMaterial = Objects[o].extra.Materials
["Front"][Q];
var
nullMat:ColorMaterial = new ColorMaterial(0x000000,{alpha:
0});
faceMat.smooth=true;
var
sideMat:BitmapMaterial = (Objects[o].extra.Materials
["Side"]!=undefined)?Objects[o].extra.Materials["Side"][Q]:Objects
[o].extra.Materials["Front"][Q];
sideMat.smooth=true;
if
(Objects[o].extra.dim.ry==90){
Objects[o].cubeMaterials.left = faceMat;
Objects[o].cubeMaterials.right = faceMat;
Objects[o].cubeMaterials.front = sideMat;
Objects[o].cubeMaterials.back = sideMat;
}else{
Objects[o].cubeMaterials.front = faceMat;
Objects[o].cubeMaterials.back = faceMat;
Objects[o].cubeMaterials.left = sideMat;
Objects[o].cubeMaterials.right = sideMat;
}
Objects[o].cubeMaterials.top = nullMat;
Objects[o].cubeMaterials.bottom = nullMat;
Objects[o].extra.Quality=Q;
Objects[o].extra.Blur=false;
}
}
}else{
if (Objects[o].extra.set){
Objects[o].extra.set =
false;
if
(Objects[o].extra.container)Objects
[o].extra.container.removeChild(Objects[o]);
else
removeChild(Objects[o]);
}
}
}
if (time>=ticktime){
for (var Co in Conts) {
//Processing of pivot
displacment in order to fight z-sorting
var Ca = new
Number3D(cam.x,cam.y,cam.z);
Ca.transform(Ca,Conts[Co].inverseSceneTransform);
var Y = Ca.y;
var X = Ca.x;
var Z = Ca.z;
if (Ca.x>Conts[Co].maxX) X =
Conts[Co].maxX;
if (Ca.x<Conts[Co].minX) X =
Conts[Co].minX;
if (Ca.z<Conts[Co].minZ) Z =
Conts[Co].minZ;
if (Ca.z>Conts[Co].maxZ) Z =
Conts[Co].maxZ;
var Piv = new Number3D(X,Y,Z);
Piv.transform(Piv,Conts[Co].sceneTransform);
if (Conts[Co].pivotPoint!=Piv){
Conts[Co].movePivot(X,Y,Z);
Conts[Co].moveTo(Piv.x,Piv.y,Piv.z);
if
(DEBUG_PIVOT)Conts[Co].extra.pivot.moveTo
(Piv.x,Piv.y,Piv.z);
}
}
time=0;
}else time++;
}
}
Hoping this will help
Cheers
On 8 oct, 09:16, Michael Iv <[email protected]> wrote:
> Enguer Hello , I am in shock of the preformance of your website.Can you
> share a few tips about texture optimization that you have done there.Because
> i am finishing a game project right now that involves a lot of different
> textures and I am struggling to encrease performance by optimizing different
> parts . But so far I am not succeeding much .
> I will very appreciate any tip.
>
>
>
> On Thu, Oct 8, 2009 at 12:36 AM, enguer <[email protected]> wrote:
>
> > Hi,
> > I finally release this project; you can find it athttp://www.bandit3.com
> > I will be glad to know your opinion about this project.
>
> > cheers
>
> > Enguer
>
> > On 28 sep, 14:42, Rob Bateman <[email protected]> wrote:
> > > Hey Enguer
>
> > > please see my previous response to this. it may not be the answer you
> > were
> > > looking for, but it should at least explain why you see what you do
>
> > > the site demo look simply amazing - be sure to let us know when it is
> > live!
>
> > > cheers
>
> > > Rob
>
> > > On Wed, Sep 23, 2009 at 5:52 PM, enguer <[email protected]> wrote:
>
> > > > Oups
> > > >http://bandit3.kob-eye.com/TestBB2.swf
>
> > > > On 23 sep, 18:52, enguer <[email protected]> wrote:
> > > > > And again with 2 box in a objectContainer3D :
> > > >http://bandit3.kob-eye.com/TestBB.swf
>
> > > > > On 23 sep, 18:43, enguer <[email protected]> wrote:
>
> > > > > > I know why my script doesnt work well... There is a bug in
> > maxX/minX
> > > > > > etc.... values.
>
> > > > > > I've create a simple example with debugbb = true and debugbs =
> > true;
> > > > > > I've supposed minX,maxX,minZ,maxZ... would be the bouding box
> > > > > > geometry.
>
> > > > > >http://bandit3.kob-eye.com/TestBB.swf
>
> > > > > > But in this example we see that the boudingbox is containing the
> > > > > > bounding sphere, and that's why minX,maxX.... doesnt represent the
> > > > > > real geometry but the geometry of the bouding sphere .... That's
> > not
> > > > > > the same.
>
> > > > > > So how can i get the real minX/maxX.... values ?
>
> > > > > > On 23 sep, 16:10, enguer <[email protected]> wrote:
>
> > > > > > > I've placed this inside the tick method (processed at each frame)
> > of
> > > > > > > each objectContainer3D (one for each block of buildings).Each
> > > > > > > objectContainer contain a spriterendersession.
> > > > > > > cam => is the camera on the scene
> > > > > > > var Ca = new
> > > > Number3D(cam.x,cam.y,cam.z);
> > > > > > > Ca.transform(Ca,);
> > > > > > > var Y = Ca.y;
> > > > > > > var X = Ca.x;
> > > > > > > var Z = Ca.z;
> > > > > > > if (Ca.x>maxX) X = maxX;
> > > > > > > if (Ca.x<minX) X = minX;
> > > > > > > if (Ca.z<minZ) Z = minZ;
> > > > > > > if (Ca.z>maxZ) Z = maxZ;
> > > > > > > var Piv = new Number3D(X,Y,Z);
>
> > Piv.transform(Piv,sceneTransform);
> > > > > > > movePivot(X,Y,Z);
> > > > > > > moveTo(Piv.x,Piv.y,Piv.z);
>
> > > > > > > This script move the pivot near the camera but inside the bouding
> > box
> > > > > > > of the objectContainer .
> > > > > > > This should Zsort each "sprite" in the right order without
> > > > > > > intersection... but it seems it doesnt work as well as it
> > should....
>
> > > > > > > On 23 sep, 15:09, Peter Kapelyan <[email protected]> wrote:
>
> > > > > > > > You can move the pivot like
>
> > > > > > > > myObject.movePivot(newX,newY,newZ);
>
> > > > > > > > is this what you needed?
>
> > > > > > > > -Pete
>
> > > > > > > > On Wed, Sep 23, 2009 at 5:16 AM, enguer <[email protected]>
> > > > wrote:
>
> > > > > > > > > Hi again :)
> > > > > > > > > Property pushback / push worked well for green plane, but
> > i've
> > > > again
> > > > > > > > > problems with z-sorting :
> > > > > > > > > Is there a way to move pivot dynamically inside his container
> > to
> > > > use
> > > > > > > > > with spriterendersession ?
> > > > > > > > > I would use this for buildings in order to eliminate
> > intersection
> > > > > > > > > between buildings and front scene objects.
>
> > > > > > > > > the pivot should place nearest to the camera inside his
> > objects
> > > > only
> > > > > > > > > on x and z axis.
>
> > > > > > > > > Have you an idea about this or should i create a custom
> > script ?
>
> > > > > > > > > On 22 sep, 18:35, enguer <[email protected]> wrote:
> > > > > > > > > > Thank you again, i will give the official link here when we
> > put
> > > > it
> > > > > > > > > > online :)
>
> > > > > > > > > > On 22 sep, 17:28, Peter Kapelyan <[email protected]>
> > wrote:
>
> > > > > > > > > > > You are welcome! Your website is probably the most
> > amazing
> > > > use of
> > > > > > > > > away3d
> > > > > > > > > > > I've seen yet, and I'm sure you'll be winning some awards
> > for
> > > > it.
>
> > > > > > > > > > > Can you let us know when your website is live, please?
>
> > > > > > > > > > > -Pete
>
> > > > > > > > > > > On Tue, Sep 22, 2009 at 10:48 AM, enguer <
> > > > [email protected]> wrote:
>
> > > > > > > > > > > > Thank you for your compliment and your good tip :p
>
> > > > > > > > > > > > On 22 sep, 16:24, Peter Kapelyan <[email protected]>
> > > > wrote:
> > > > > > > > > > > > > Did I mention it looks super awesome? :)
>
> > > > > > > > > > > > > Also you can use:
>
> > > > > > > > > > > > > myThinginBack.pushBack=true;
>
> > > > > > > > > > > > > And if those things don't help, theres more ways to
> > do
> > > > sorting, so
> > > > > > > > > let us
> > > > > > > > > > > > > know if you have problems!
>
> > > > > > > > > > > > > -Pete
>
> > > > > > > > > > > > > On Tue, Sep 22, 2009 at 10:04 AM, enguer <
> > > > [email protected]>
> > > > > > > > > wrote:
>
> > > > > > > > > > > > > > WOW !! it works !!
>
> > > > > > > > > > > > > > thanks a lot , now i need to set this on other bugs
> > :)
>
> > > > > > > > > > > > > > On 22 sep, 15:50, Peter Kapelyan <
> > [email protected]>
> > > > wrote:
> > > > > > > > > > > > > > > Try this:
>
> > > > > > > > > > > > > > > myGreenPlane.pushFront=true;
>
> > > > > > > > > > > > > > > It looks really good!
>
> > > > > > > > > > > > > > > Let me know if it works for you.
>
> > > > > > > > > > > > > > > -Pete
>
> > > > > > > > > > > > > > > On Tue, Sep 22, 2009 at 9:37 AM, enguer <
> > > > [email protected]>
> > > > > > > > > > > > wrote:
>
> > > > > > > > > > > > > > > > Hi all,
> > > > > > > > > > > > > > > > I have a little problems with a plane against a
> > > > wall. this
> > > > > > > > > plane is
> > > > > > > > > > > > > > > > distant from about 5 px.
> > > > > > > > > > > > > > > > Some parts of this plane is disappearing.
> > > > > > > > > > > > > > > > You can see this plane (the green one) on this
> > url
> > > > :
> > > > > > > > > > > > > > > >http://bandit3.kob-eye.com/index2.html
>
> > > > > > > > > > > > > > > > A triangle disapear at the top left of this
> > green
> > > > plane, when
> > > > > > > > > you
> > > > > > > > > > > > > > > > place your mouse at the top left of your
> > screen.
>
> > > > > > > > > > > > > > > > if someone could give an advice ?
>
> > > > > > > > > > > > > > > --
> > > > > > > > > > > > > > > ___________________
>
> > > > > > > > > > > > > > > Actionscript 3.0 Flash 3D Graphics Engine
>
> > > > > > > > > > > > > > > HTTP://AWAY3D.COM
>
> > > > > > > > > > > > > --
> > > > > > > > > > > > > ___________________
>
> > > > > > > > > > > > > Actionscript 3.0 Flash 3D Graphics Engine
>
> > > > > > > > > > > > > HTTP://AWAY3D.COM
>
> > > > > > > > > > > --
> > > > > > > > > > > ___________________
>
> > > > > > > > > > > Actionscript 3.0 Flash 3D Graphics Engine
>
> > > > > > > > > > > HTTP://AWAY3D.COM
>
> > > > > > > > --
> > > > > > > > ___________________
>
> > > > > > > > Actionscript 3.0 Flash 3D Graphics Engine
>
> > > > > > > > HTTP://AWAY3D.COM
>
> > > --
> > > Rob Bateman
> > > Flash Development & Consultancy
>
> > > [email protected]