Exemplo n.º 1
0
 void traverseCompositeTree(IModelTreeComponent component, IntermediateMap map, int offsetX, int offsetY, int offsetZ)
 {
     if (component is ModelLeaf)
     {
         ModelLeaf model = (ModelLeaf)component;
         for (int x = 0; x < model.sizeX; x++)
         {
             for (int y = 0; y < model.sizeY; y++)
             {
                 for (int z = 0; z < model.sizeZ; z++)
                 {
                     int colourIndex = model.data[x, y, z]; //Implicit conversion
                     map.setBlockAt(offsetX + x, offsetY + y, offsetZ + z, new Block(colourIndex));
                 }
             }
         }
     }
     else if (component is ModelTree)
     {
         ModelTree tree = (ModelTree)component;
         foreach (IModelTreeComponent child in tree.components)
         {
             traverseCompositeTree(child, map, offsetX + tree.offsetX, offsetY + tree.offsetY, offsetZ + tree.offsetZ);
         }
     }
 }
Exemplo n.º 2
0
 void assembleTree()
 {
     if (chunkComponents.Count == 0)
     {
         masterNode = new ModelTree(0);
         foreach (ModelLeaf leaf in leafComponents.Values)
         {
             masterNode.components.Add(leaf);
         }
     }
     else
     {
         masterNode = chunkComponents.GetValueOrDefault(0, null);
         if (masterNode == null)
         {
             throw new Exception("Parcel did not contain master node!");
         }
         foreach (int chunkID in masterNode.childChunks)
         {
             IModelTreeComponent component = fetchComponent(chunkID, 0, 0, 0);
             if (component != null)
             {
                 masterNode.components.Add(component);
             }
         }
     }
 }
Exemplo n.º 3
0
        IModelTreeComponent fetchComponent(int id, int translationX, int translationY, int translationZ)
        {
            ModelTree result = chunkComponents.GetValueOrDefault(id, null);

            if (result == null)
            {
                throw new Exception("Vox referenced chunk ID " + id + " but didn't contain it");
            }
            if (result.childChunks.Count == 0)
            {
                if (result.childModels.Count == 0)
                {
                    Console.WriteLine("Encountered component with no children ID " + id);
                    return(null);
                }
                else
                {
                    if (translationX + translationY + translationZ == 0 && result.childModels.Count == 1)
                    {
                        return(leafComponents.GetValueOrDefault(0, null)); //Squeeze node away
                    }
                    else
                    {
                        result.offsetX += translationX;
                        result.offsetY += translationY;
                        result.offsetZ += translationZ;
                        foreach (int modelID in result.childModels)
                        {
                            result.components.Add(leafComponents.GetValueOrDefault(modelID));
                        }
                        return(result);
                    }
                }
            }
            else if (result.childChunks.Count == 1)
            {
                return(fetchComponent(result.childChunks[0], translationX + result.offsetX, translationY + result.offsetY, translationZ + result.offsetZ)); //Squeeze node away
            }
            else
            {
                result.offsetX += translationX;
                result.offsetY += translationY;
                result.offsetZ += translationZ;
                foreach (int chunkID in result.childChunks)
                {
                    IModelTreeComponent component = fetchComponent(chunkID, 0, 0, 0);
                    if (component != null)
                    {
                        result.components.Add(component);
                    }
                }
                return(result);
            }
        }