public Region(StaticGeometry parent, string name, SceneManager mgr, UInt32 regionID, Vector3 center) { this.parent = parent; this.name = name; this.sceneMgr = mgr; this.regionID = regionID; this.center = center; queuedSubMeshes = new List <QueuedSubMesh>(); lodSquaredDistances = new List <float>(); aabb = new AxisAlignedBox(); lodBucketList = new List <LODBucket>(); shadowRenderables = new ShadowRenderableList(); }
public Region(StaticGeometry parent, string name, SceneManager mgr, UInt32 regionID, Vector3 center) { this.parent = parent; this.name = name; this.sceneMgr = mgr; this.regionID = regionID; this.center = center; queuedSubMeshes = new List<QueuedSubMesh>(); lodSquaredDistances = new List<float>(); aabb = new AxisAlignedBox(); lodBucketList = new List<LODBucket>(); shadowRenderables = new ShadowRenderableList(); }
public Region(StaticGeometry parent, string name, SceneManager mgr, UInt32 regionID, Vector3 center) : base(name) { MovableType = "StaticGeometry"; this.parent = parent; this.sceneMgr = mgr; this.regionID = regionID; this.center = center; this.queuedSubMeshes = new List <QueuedSubMesh>(); this.lodValues = new LodValueList(); this.aabb = new AxisAlignedBox(); this.lodBucketList = new List <LODBucket>(); this.shadowRenderables = new ShadowRenderableList(); }
/// <summary> /// Remove & destroy a StaticGeometry instance. /// </summary> public void DestroyStaticGeometry( StaticGeometry geom ) { DestroyStaticGeometry( geom.Name ); }
/// <summary> /// Creates a StaticGeometry instance suitable for use with this /// SceneManager. /// </summary> /// <remarks> /// StaticGeometry is a way of batching up geometry into a more /// efficient form at the expense of being able to move it. Please /// read the StaticGeometry class documentation for full information. /// </remarks> /// <param name="name">The name to give the new object</param> /// <param name="logLevel"></param> /// <returns>The new StaticGeometry instance</returns> public StaticGeometry CreateStaticGeometry( string name, int logLevel ) { // Check not existing if ( this.staticGeometryList.ContainsKey( name ) ) { throw new AxiomException( "StaticGeometry with name '" + name + "' already exists!" ); } StaticGeometry geometry = new StaticGeometry( this, name, logLevel ); this.staticGeometryList[ name ] = geometry; return geometry; }
// Lock the node dictionary, and rebuild the static // geometry for objects of this kind protected void Rebuild(SceneManager mgr, Dictionary<long, WorldEntity> nodeDictionary) { log.DebugFormat("Entering StaticGeometryHelper.Rebuild for geometry '{0}'", name); long tickStart = TimeTool.CurrentTime; try { nodesAddedSinceLastRebuild = 0; nodesRemovedSinceLastRebuild = 0; force = false; Monitor.Enter(mgr); if (objectGeometry != null) objectGeometry.Reset(); else objectGeometry = new StaticGeometry(mgr, name); // Dictionary mapping Material into a list of // ObjectNodes in which some submesh uses the material Dictionary<Material, MaterialAndNodeCounts> materialsUsedMap = new Dictionary<Material, MaterialAndNodeCounts>(); lock(nodeDictionary) { foreach (WorldEntity entity in nodeDictionary.Values) { if (entity is ObjectNode) { ObjectNode node = (ObjectNode)entity; // For now, we only consider "props" that have an associated SceneNode // and are direct descendants of the root scene node, and are of the right // kind, i.e., don't have a perception radius if this static geometry is for // little nodes, and vice versa. // log.DebugFormat("StaticGeometry.Rebuild: Examining node {0}, oid {1}, type {2}, sceneNode {3}, InStaticGeometry {4}, top-level {5}", // node.Name, node.Oid, node.ObjectType, node.SceneNode, node.InStaticGeometry, node.SceneNode.Parent == mgr.RootSceneNode); if (node.ObjectType == ObjectNodeType.Prop && (node.InStaticGeometry || (node.SceneNode != null && node.SceneNode.Parent == mgr.RootSceneNode)) && RightKind(node)) { foreach (Material m in node.Entity.SubEntityMaterials) { MaterialAndNodeCounts nodesUsingMaterial; if (!materialsUsedMap.TryGetValue(m, out nodesUsingMaterial)) { nodesUsingMaterial = new MaterialAndNodeCounts(); materialsUsedMap[m] = nodesUsingMaterial; } nodesUsingMaterial.materialUseCount++; int subMeshUseCount; Dictionary<ObjectNode, int> submeshUseCounts = nodesUsingMaterial.submeshUseCounts; if (!submeshUseCounts.TryGetValue(node, out subMeshUseCount)) submeshUseCounts[node] = 1; else submeshUseCounts[node] = subMeshUseCount + 1; } } } } } // Now we have a count of uses of each material, and // for each node, the number of subentities that use the // material. Now we need to calculate the number of // instance of sharings for each object node Dictionary<ObjectNode, bool> candidateNodes = new Dictionary<ObjectNode, bool>(); foreach (MaterialAndNodeCounts counts in materialsUsedMap.Values) { if (counts.materialUseCount > 1) { foreach (KeyValuePair<ObjectNode, int> pair in counts.submeshUseCounts) candidateNodes[pair.Key] = true; } } Dictionary<ObjectNode, int> staticNodes = new Dictionary<ObjectNode, int>(); foreach (KeyValuePair<ObjectNode, bool> pair in candidateNodes) { ObjectNode candidate = pair.Key; bool useIt = pair.Value; if (useIt) staticNodes[candidate] = 0; } if (staticNodes.Count == 0) log.InfoFormat("StaticGeometryHelper.Rebuild: Didn't build static geometry {0} because object count was zero", name); else { log.InfoFormat("StaticGeometryHelper.Rebuild: {0} ObjectNodes", staticNodes.Count); foreach(ObjectNode staticNode in staticNodes.Keys) { SceneNode sc = staticNode.SceneNode; if (!staticNode.InStaticGeometry) { sc.RemoveFromParent(); staticNode.InStaticGeometry = true; } log.DebugFormat("StaticGeometryHelper.Rebuild: Add node {0} with name {1} to static geometry", staticNode.Oid, staticNode.Name); objectGeometry.AddSceneNode(sc); } } if (lastStaticNodes != null) { foreach(ObjectNode node in lastStaticNodes.Keys) { if (!staticNodes.ContainsKey(node)) { // Only 1 instance of the mesh, so make sure that if in a former build it was in // static geometry, that we add it back to the scene graph. if (node.InStaticGeometry) { SceneNode sn = node.SceneNode; if (sn != null) mgr.RootSceneNode.AddChild(sn); node.InStaticGeometry = false; } } } } if (staticNodes.Count > 0) objectGeometry.Build(); lastStaticNodes = staticNodes; timeOfLastRebuild = TimeTool.CurrentTime; } finally { Monitor.Exit(mgr); } log.InfoFormat("StaticGeometryHelper.Rebuild: Rebuild of geometry '{0}' took {1} ms", name, TimeTool.CurrentTime - tickStart); }
public StaticGeometryHelper(WorldManager worldMgr, StaticGeometryKind kind, int rebuildTimeThreshold, int nodesAddedThreshold, int nodesRemovedThreshold, int nodesAddedInLastSecondThreshold) { this.worldMgr = worldMgr; this.kind = kind; this.name = (kind == StaticGeometryKind.BigOrLittleNode ? "StaticGeom" : (kind == StaticGeometryKind.BigNode ? "BigNodes" : "LittleNodes")); this.objectGeometry = null; this.rebuildTimeThreshold = rebuildTimeThreshold; this.nodesAddedThreshold = nodesAddedThreshold; this.nodesRemovedThreshold = nodesRemovedThreshold; this.nodesAddedInLastSecondThreshold = nodesAddedInLastSecondThreshold; this.nodesAddedSinceLastRebuild = 0; this.nodesRemovedSinceLastRebuild = 0; this.lastNodesAdded = 0; this.timeOfLastRebuild = 0; this.lastRebuildCheckTime = 0; this.enabled = false; this.force = false; }
public Region( StaticGeometry parent, string name, SceneManager mgr, UInt32 regionID, Vector3 center ) : base( name ) { MovableType = "StaticGeometry"; this.parent = parent; this.sceneMgr = mgr; this.regionID = regionID; this.center = center; this.queuedSubMeshes = new List<QueuedSubMesh>(); this.lodValues = new LodValueList(); this.aabb = new AxisAlignedBox(); this.lodBucketList = new List<LODBucket>(); this.shadowRenderables = new ShadowRenderableList(); }
/// <summary> /// Creates a StaticGeometry instance suitable for use with this /// SceneManager. /// </summary> /// <remarks> /// StaticGeometry is a way of batching up geometry into a more /// efficient form at the expense of being able to move it. Please /// read the StaticGeometry class documentation for full information. /// </remarks> ///<param name="name">The name to give the new object</param> ///<returns>The new StaticGeometry instance</returns> public StaticGeometry CreateStaticGeometry(string name) { // Check not existing if (staticGeometryList.ContainsKey(name)) throw new Exception("StaticGeometry with name '" + name + "' already exists! In " + "SceneManager.CreateStaticGeometry"); StaticGeometry geometry = new StaticGeometry(this, name); staticGeometryList[name] = geometry; return geometry; }