Friday 25 March 2011

Hunting down the Bake code.

So after a bit of sweat and tears I tracked down the client side bake code.
I suspect that maybe the reason why the NPCs stay as clouds (in addition to all the other properties I've not set right in e.g. the AgentCircuitData) that due to the convoluted way baked textures get passed around, the NPC code will be missing the bake code.

The way it appears to work to display the avatars to the rest of the connected clients is this: Scene gets a request to create an avatar in a scenepresence so it sends a request for baked textures to the client because the baking isn't done on the server. (Was it done on the server before? i.e. why did it work in 0.6.9? Need to investigate how 0.6.9 did it).

Anyways, the way it works *now* is that the client then receives the textures from the servers which it has to bake or else it picks up the textures it has from its cache. At that point it runs the baking code, effectively compressing all the different jpeg (or whatever) layers into a single jpeg (or whatever). This "baked" image is then sent back up to the Scene on the server. This is done for each texture for each section of the avatar's body (i.e. head, upper body and lower body). There are also alpha layers ant whatnot but I don't fully understand how those work.

Once the Scene has received the appropriate bakedtextures it somehow allocates them as temporary assets and associates them somehow with the agent or with the scenepresence(?) - a little unclear on the *exact* mechanics but more or less that's it.

Next step is it sends the baked textures down to all the other scenepresences in the scene. What that means is that only your own client has the real textures for your avatar. Everybody else only has baked textures, which makes it difficult for other viewers to rip your content out of the scene.

Anyways, the corresponding bake code is in the libopenmetaverse. I can't find any bake code like that in imprudence. It has to be there but I can't find it. Any case, in an ideal world we want C# and not have to convert from C++ to C# so libopenmetaverse is probably the best choice.

The code module is ibopenmetaverse/trunk/openmetaverse/imaging/bakelayer.cs
How this code is used can be found in the radegast code also: look for code like oven.bake and oven.addtexture to locate it in the radegast code (appearancemanage.cs in the radegast trunk). So in theory that's all the code you need to get the baking implemented.

I was hoping there was an easier way to do it than this, but if not well at least I know where to look for the relevant code.

Also: opensim does use some libraries from openmetaverse but I'm unclear on whether the package required to do the baking is in or not. The required package is OpenMetaverse.Imaging.

If it's not in it, then there's a further dependency on OpenMetaverse.Assets.

The following are the required "usings" in the bakelayer.cs code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using OpenMetaverse.Assets;

namespace OpenMetaverse.Imaging

No comments:

Post a Comment