예제 #1
0
        //public static void Register(ISg sg, TraversalState state)
        //{
        //    var replace = s_tileUsage.ContainsKey(sg) ? s_tileUsage[sg] : DateTime.MinValue;
        //    s_tileUsage[sg] = replace;
        //}

        // private static bool m_forceFreeMemory = false;
        public static void Use(ISg sg, TraversalState state)
        {
            //if (s_tileUsage.ContainsKey(sg))
            //    s_tileUsage.Remove(sg);

            s_tileUsage[sg] = (long)(DateTime.Now - s_startTime).TotalSeconds;

            //if (GC.GetTotalMemory(false) > 600000000)
            //    m_forceFreeMemory = true;
        }
예제 #2
0
        public ISg SetParameters(AbstractTraversal t)
        {
            if (!m_isInitialized)
            {
                var info = m_instance.PatchFileInfo;
                var bb   = m_instance.PositionsType == PositionsType.V3dPositions ?
                           info.LocalBoundingBox : info.LocalBoundingBox2d;

                var patch = new StreamingJob(
                    () =>
                {
                    //TaskCombinators.Delay(100);
                    //do importer logic here

                    var patchVg = m_instance.LoadingStrategy.Load(m_instance.PatchFileInfo, m_instance.PatchFilePath, m_instance.PositionsType,
                                                                  true, true, true, m_instance.MaxTriangleSize);

                    if (patchVg == null)
                    {
                        return(EmptyLeaf.Singleton);
                    }

                    var lodColor        = Patch.GetLodColor(m_instance.Level, m_instance.MaxLevel);
                    patchVg["LodColor"] = lodColor;

                    for (int i = 0; i < patchVg.Textures.Count; i++)
                    {
                        var key = patchVg.Textures.Keys.ToList()[i];

                        var source         = patchVg.Textures[key].Convertible;
                        Convertible target = null;

                        if (t.Renderer is SlimDx9Renderer)
                        {
                            target = SlimDx9TextureConvertible.Create(
                                new SlimDx9TextureConvertible.SlimDx9TextureParameters()
                            {
                                //SlimDx9Format = SlimDX.Direct3D9.Format., // .Dxt5,
                                Pool = SlimDX.Direct3D9.Pool.Default
                            });
                            source.ConvertInto(target);
                        }
                        else
                        {
                            // nothing todo in slimdx10renderer (this just loads the texture on demand)
                            // fix this if you are fed up with framerate hick ups
                            target = source;
                        }

                        patchVg.Textures[key] = new Texture(target);
                    }
                    lock (asyncLock)
                    {
                        m_asyncTextures = patchVg.Textures;
                    }

                    return(patchVg.ToVertexGeometrySet());
                },
                    bb, m_instance.MaxLevel - m_instance.Level, true);

                patch.DestructSideEffects = DisposeSideEffects;

                var placeHolder = Primitives.WireBox(bb, C4b.Red).ToVertexGeometrySet();

                m_returnISg = new AsyncStreamingNode(patch, placeHolder)
                {
                    DebugName = Path.GetFileName(m_instance.PatchFilePath),
                };

                var local2Global = m_instance.PatchFileInfo.GetLocal2Global(m_instance.PositionsType);

                if (m_instance.InvertZ)
                {
                    local2Global = M44d.Scale(1, 1, -1) * local2Global;
                }

                var global2Local = local2Global.Inverse;
                m_returnISg = Rsg.Apply(Rsg.Attribute.PushTrafo3d(new Trafo3d(local2Global, global2Local)), m_returnISg);

                m_isInitialized = true;
            }

            return(m_returnISg);
        }
예제 #3
0
        public static ISg WithVertexAttribute(this ISg sg, string semantic, Array data)
        {
            var bufferView = new BufferView(AValModule.constant((IBuffer) new ArrayBuffer(data)), data.GetType().GetElementType());

            return(new Sg.VertexAttributeApplicator(Symbol.Create(semantic), bufferView, AValModule.constant(sg)));
        }
예제 #4
0
        private static ISg LodBoxHierarchy(
            int level, Volume <ISg> vgsVolume, LevelOfDetailSettings settings, int maxLevel)
        {
            int detailCount = 1;

            if (vgsVolume.SX > 1)
            {
                detailCount *= 2;
            }
            if (vgsVolume.SY > 1)
            {
                detailCount *= 2;
            }
            if (vgsVolume.SZ > 1)
            {
                detailCount *= 2;
            }

            //detail count is 1 when space is not dividable
            #region detailCount == 1
            if (detailCount == 1)
            {
                //if level > 0 keep subsampling without subdivision
                if (level > 0) //|| ( level == 0 && (vgsVolume[0, 0, 0].TileSize.X > 256 || vgsVolume[0, 0, 0].TileSize.Y > 256)))
                {
                    var detailNodeList = LodBoxHierarchy(level - 1, vgsVolume, settings, maxLevel).IntoList();

                    var dist = DistanceFunc(level - 1, settings);

                    Report.Line("LOD.cs Level " + level + " " + dist);

                    var box = new Sg.LodBox()
                    {
                        Name        = "level" + level,
                        DetailNodes = detailNodeList,
                        Settings    = new LodBoxSettings
                        {
                            Distance           = dist,
                            DeciderCombination = "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance",
                        },
                    };

                    box["TileLayout"] = GetTileLayout(vgsVolume.Dim);
                    return(box);
                }

                return(vgsVolume[0, 0, 0]);
            }
            #endregion

            var detailNodes = new List <ISg>(detailCount);
            for (int i = 0; i < 8; i++)
            {
                bool valid  = true;
                V3l  origin = V3l.Zero;
                V3l  length = vgsVolume.Size;

                //compute splitting dimensions for each axis
                for (int dim = 0; dim < 3; dim++)
                {
                    if ((i & (1 << dim)) == 0)
                    {
                        if (length[dim] > 1)
                        {
                            length[dim] /= 2;
                        }
                    }
                    else
                    {
                        if (length[dim] > 1)
                        {
                            origin[dim] = length[dim] / 2;
                            length[dim] = length[dim] - origin[dim];
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                }

                if (valid)
                {
                    ISg detailNode =
                        LodBoxHierarchy(level - 1, vgsVolume.SubVolume(origin, length), settings, maxLevel);
                    detailNodes.Add(detailNode);
                }
            }

            {
                var dist = LevelOfDetail.DistanceFunc(level - 1, settings);

                //Report.Line("LOD.cs Level " + level + " " + dist);

                bool isMax = false; // level == maxLevel;

                var box = new Sg.LodBox()
                {
                    Name        = "level" + level,
                    DetailNodes = detailNodes,
                    Pinned      = Sg.LodBox.PinnedOptions.Default,
                    Settings    = new LodBoxSettings
                    {
                        Distance           = dist,
                        DeciderCombination = !isMax ? "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance"
                        : "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => false",
                    },
                };

                // s_numOfBoxes++;

                box["TileLayout"] = GetTileLayout(vgsVolume.Dim);

                //Report.Line("DIM: " + vgsVolume.Dim.ToString() + " "
                //    + box["TileLayout"].ToString() + " __lvl: "
                //    + level + " Desc.: " + box.DetailNodes.Count());

                var sg = Rsg.Apply(
                    new ResourcePinningEnabledValue()
                {
                    Value = level == maxLevel
                }, box);

                return(box);
            }
        }