/// <summary> /// Add all the unique scripts from shape list to the dictionary /// </summary> private void AddScriptsRecursively(ShapeCollection shapes, ref Dictionary <string, int> scriptsDictionaryOut) { ShapeComponentType scriptComponentType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VScriptComponent"); foreach (ShapeBase shape in shapes) { if (shape.HasChildren()) { AddScriptsRecursively(shape.ChildCollection, ref scriptsDictionaryOut); } if (shape.Components == null) { continue; } foreach (ShapeComponent comp in shape.Components) { if (comp.CollectionType == scriptComponentType) { string script = comp.GetPropertyByName("ScriptFile").Value.ToString(); if (string.IsNullOrEmpty(script)) { continue; } int references = 0; scriptsDictionaryOut.TryGetValue(script, out references); scriptsDictionaryOut[script] = references + 1; } } } }
/// <summary> /// Overridden function /// </summary> protected override void OnSaved() { if (ConfigureShapeComponentsPanel.PanelInstance == null || !EditorManager.Settings.SyncOnExposeVarsAfterSaving) { return; } // Saving a script should also validate it ValidateScriptDocumentAutomatic(_currentDoc); bool containsOnExposeNow = _currentDoc != null && _currentDoc.ScintillaControl.Text.Contains("OnExpose"); //don't sync OnExpose vars if there is and was no OnExpose Callback if (!_containsOnExpose && !containsOnExposeNow) { return; } _containsOnExpose = containsOnExposeNow; ShapeComponentType scriptComponentType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VScriptComponent"); if (ShapeComponent.UsedComponents.ContainsKey(scriptComponentType)) { // de-active script caching so the script will be reloaded in all cases bool bOldScriptCaching = EditorManager.Settings.UseScriptCachingInEditor; if (bOldScriptCaching) { EditorManager.Settings.UseScriptCachingInEditor = false; } foreach (ShapeComponent scriptComponent in ShapeComponent.UsedComponents[scriptComponentType]) { string scriptFile = scriptComponent.GetPropertyByName("ScriptFile").Value.ToString(); scriptFile = EditorManager.Project.MakeAbsolute(scriptFile); if (scriptFile == _currentDoc.AbsSourceFilename) { ((ShapeBase)scriptComponent.Owner).PerformPostEngineInstanceCreationSetup(false); } } // Restore script caching setting if (bOldScriptCaching) { EditorManager.Settings.UseScriptCachingInEditor = true; } } // Refresh the property grid of the components panel ConfigureShapeComponentsPanel.PanelInstance.InvalidatePropertyGrid(); }
ShapeComponent CreateScriptComponent(string scriptFileName) { ShapeComponentType t = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VScriptComponent"); if (t == null) { return(null); } ShapeComponent comp = (ShapeComponent)t.CreateInstance(null); comp.SetPropertyValue("ScriptFile", scriptFileName); return(comp); }
ShapeComponent CreateLightClippingComponent(CustomVolumeShape volume) { ShapeComponentType t = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VLightClippingVolumeComponent"); Assert.IsNotNull(t); if (t == null) { return(null); } ShapeComponent comp = (ShapeComponent)t.CreateInstance(null); comp.SetPropertyValue("Volume", volume); return(comp); }
public bool Build(ShapeCollection staticGeometries, ref int numGeometryVertices, ref int numGeometryTriangles) { if (!HasEngineInstance()) { return(false); } EngineNavMesh.ClearNavMesh(); EngineNavMesh.ClearGeometry(); EngineNavMesh.ClearCarvers(); EngineNavMesh.ClearSeedPoints(); EngineNavMesh.ClearLocalSettings(); EngineNavMesh.ClearDecorationCapsules(); SetEngineInstanceBaseProperties(); HavokNavMeshGlobalSettings globalSettings = GetGlobalSettings(); if (globalSettings == null) { return(false); } BoundingBox parentZoneBbox = new BoundingBox(); if (globalSettings.RestrictToInputGeometryFromSameZone && ParentZone != null) { parentZoneBbox = ParentZone.CalculateBoundingBox(); } // check if there's a parent zone foreach (ShapeBase shape in staticGeometries) { // treat as cutter if flag is set and if in different zone bool potentiallyTreatAsCutter = globalSettings.RestrictToInputGeometryFromSameZone && (shape.ParentZone != ParentZone); if (shape is EntityShape) { EntityShape entity = shape as EntityShape; eNavMeshUsage usage = entity.GetNavMeshUsage(); // exclude entities that have a vHavokRigidBody component with "Motion Type" != "Fixed" ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("vHavokRigidBody"); if (compType != null && entity.Components != null) { ShapeComponent comp = entity.Components.GetComponentByType(compType); if (comp != null) { string propValue = comp.GetPropertyValue("Motion Type") as string; if (string.Compare(propValue, "Fixed") != 0) { usage = eNavMeshUsage.ExcludeFromNavMesh; } } } // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddEntityGeometry(entity.EngineEntity.GetNativeObject(), (int)usage, parentZoneBbox); } } else if (shape is StaticMeshShape) { StaticMeshShape staticMesh = shape as StaticMeshShape; eNavMeshUsage usage = staticMesh.GetNavMeshUsage(); // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddStaticMeshGeometry(staticMesh.EngineMesh.GetNativeObject(), (int)usage, parentZoneBbox); } } else if (shape is TerrainShape) { TerrainShape terrain = shape as TerrainShape; eNavMeshUsage usage = terrain.GetNavMeshUsage(); // potentially override usage if (potentiallyTreatAsCutter && (usage == eNavMeshUsage.IncludeInNavMesh)) { usage = eNavMeshUsage.CutterOnly; } if (usage != eNavMeshUsage.ExcludeFromNavMesh) { EngineNavMesh.AddTerrainGeometry(terrain.EngineTerrain.GetNativeObject(), (int)usage, parentZoneBbox); } } #if !HK_ANARCHY else if (shape is DecorationGroupShape) { DecorationGroupShape decorationGroup = shape as DecorationGroupShape; // Please note that currently the native HavokAiEnginePlugin only supports decoration capsules as cutters. if (decorationGroup.GetNavMeshLimitedUsage() == DecorationGroupShape.eNavMeshLimitedUsage.CutterOnly) { EngineNavMesh.AddDecorationGroupCapsules(decorationGroup.EngineGroup.GetGroupsObject()); } } #endif #if USE_SPEEDTREE else if (shape is Speedtree6GroupShape) { Speedtree6GroupShape trees = shape as Speedtree6GroupShape; if (trees.EnableCollisions) { EngineNavMesh.AddSpeedTree6Capsules(trees.EngineGroup.GetGroupsObject()); } } #endif } numGeometryVertices = EngineNavMesh.GetNumGeometryVertices(); numGeometryTriangles = EngineNavMesh.GetNumGeometryTriangles(); // Add carvers ShapeCollection carvers = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshCarverShape)); foreach (ShapeBase shape in carvers) { HavokNavMeshCarverShape carver = shape as HavokNavMeshCarverShape; BoundingBox localBbox = null; carver.GetLocalBoundingBox(ref localBbox); localBbox.vMin.X *= carver.ScaleX; localBbox.vMin.Y *= carver.ScaleY; localBbox.vMin.Z *= carver.ScaleZ; localBbox.vMax.X *= carver.ScaleX; localBbox.vMax.Y *= carver.ScaleY; localBbox.vMax.Z *= carver.ScaleZ; EngineNavMesh.AddBoxCarver(localBbox.vMin, localBbox.vMax, carver.Position, carver.RotationMatrix, carver.IsInverted()); } // Add seed points ShapeCollection seedPoints = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshSeedPointShape)); foreach (ShapeBase shape in seedPoints) { HavokNavMeshSeedPointShape seedPoint = shape as HavokNavMeshSeedPointShape; EngineNavMesh.AddSeedPoint(seedPoint.Position); } // Add local settings ShapeCollection localSettings = EditorManager.Scene.AllShapesOfType(typeof(HavokNavMeshLocalSettingsShape)); foreach (ShapeBase shape in localSettings) { HavokNavMeshLocalSettingsShape ls = shape as HavokNavMeshLocalSettingsShape; BoundingBox bbox = null; ls.GetLocalBoundingBox(ref bbox); bbox.vMin.X *= ls.ScaleX; bbox.vMin.Y *= ls.ScaleY; bbox.vMin.Z *= ls.ScaleZ; bbox.vMax.X *= ls.ScaleX; bbox.vMax.Y *= ls.ScaleY; bbox.vMax.Z *= ls.ScaleZ; // Nav Mesh Generation Settings EngineNavMesh.m_maxWalkableSlope = ls.MaxWalkableSlope / 180.0f * 3.14159f; // Nav Mesh Edge Matching Settings EngineNavMesh.m_maxStepHeight = ls.MaxStepHeight; EngineNavMesh.m_maxSeparation = ls.MaxSeparation; EngineNavMesh.m_maxOverhang = ls.MaxOverhang; EngineNavMesh.m_cosPlanarAlignmentAngle = (float)Math.Cos(ls.PlanarAlignmentAngle / 180.0f * 3.14159f); EngineNavMesh.m_cosVerticalAlignmentAngle = (float)Math.Cos(ls.VerticalAlignmentAngle / 180.0f * 3.14159f); EngineNavMesh.m_minEdgeOverlap = ls.MinEdgeOverlap; // Nav Mesh Simplification Settings EngineNavMesh.m_maxBorderSimplifyArea = ls.MaxBorderSimplifyArea; EngineNavMesh.m_maxConcaveBorderSimplifyArea = ls.MaxConcaveBorderSimplifyArea; EngineNavMesh.m_useHeightPartitioning = ls.UseHeightPartitioning; EngineNavMesh.m_maxPartitionHeightError = ls.MaxPartitionHeightError; // Nav Mesh Simplification Settings (Advanced) EngineNavMesh.m_minCorridorWidth = ls.MinCorridorWidth; EngineNavMesh.m_maxCorridorWidth = ls.MaxCorridorWidth; EngineNavMesh.m_holeReplacementArea = ls.HoleReplacementArea; EngineNavMesh.m_maxLoopShrinkFraction = ls.MaxLoopShrinkFraction; EngineNavMesh.m_maxBorderHeightError = ls.MaxBorderHeightError; EngineNavMesh.m_maxBorderDistanceError = ls.MaxBorderDistanceError; EngineNavMesh.m_maxPartitionSize = ls.MaxPartitionSize; EngineNavMesh.m_useConservativeHeightPartitioning = ls.UseConservativeHeightPartitioning; EngineNavMesh.m_hertelMehlhornHeightError = ls.HertelMehlhornHeightError; EngineNavMesh.m_cosPlanarityThreshold = (float)Math.Cos(ls.PlanarityThreshold / 180 * 3.14159f); EngineNavMesh.m_nonconvexityThreshold = ls.NonconvexityThreshold; EngineNavMesh.m_boundaryEdgeFilterThreshold = ls.BoundaryEdgeFilterThreshold; EngineNavMesh.m_maxSharedVertexHorizontalError = ls.MaxSharedVertexHorizontalError; EngineNavMesh.m_maxSharedVertexVerticalError = ls.MaxSharedVertexVerticalError; EngineNavMesh.m_maxBoundaryVertexHorizontalError = ls.MaxBoundaryVertexHorizontalError; EngineNavMesh.m_maxBoundaryVertexVerticalError = ls.MaxBoundaryVertexVerticalError; EngineNavMesh.m_mergeLongestEdgesFirst = ls.MergeLongestEdgesFirst; EngineNavMesh.AddLocalSettings(bbox.vMin, bbox.vMax, ls.Position, ls.RotationMatrix); } // todo: figure out how to pass class instances between here and EngineNavMesh. // basically the settings members of EngineNavMesh are reused for transferring the local settings to // EngineNavMesh. this should be harmless due to the following call which will revert any changes. SetEngineInstanceBaseProperties(); string fullSnapshotPath = Path.Combine(CSharpFramework.EditorManager.Scene.Project.ProjectDir, m_snapshotFilename); bool ret = EngineNavMesh.BuildNavMeshFromGeometry(m_saveInputSnapshot, fullSnapshotPath); EngineNavMesh.ClearGeometry(); EngineNavMesh.ClearCarvers(); EngineNavMesh.ClearSeedPoints(); EngineNavMesh.ClearLocalSettings(); EngineNavMesh.ClearDecorationCapsules(); return(ret); }
private void ApplySettingsOnScene() { // Set Renderer if (radioButton_Forward.Checked) { _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_FORWARD; } else if (radioButton_ForwardMobile.Checked) { _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_MOBILE_FORWARD; } else if (radioButton_Deferred.Checked) { _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_DEFERRED; } else if (radioButton_NoRenderer.Checked) { _scene.V3DLayer.RendererNodeClass = IRendererNodeManager.RENDERERNODECLASS_SIMPLE; return; } // Enable Post Processors ShapeComponentType[] compTypes = EditorManager.RendererNodeManager.ComponentTypes; _scene.V3DLayer.RendererSetup._rendererComponents.Clear(); EditorManager.RendererNodeManager.RemovePostprocessors(); foreach (ShapeComponentType compType in compTypes) { if (compType.Hidden) { continue; } if (!EditorManager.RendererNodeManager.CanAttachPostprocessor(compType.ProbeComponent)) { continue; } bool bEnable = false; if (compType.UniqueName.Equals("VPostProcessSSAO")) { bEnable = checkBox_SSAO.Checked; } else if (compType.UniqueName.Equals("VPostProcessGlow")) { bEnable = checkBox_Glow.Checked; } else if (compType.UniqueName.Equals("VPostProcessDepthOfField")) { bEnable = checkBox_DOF.Checked; } else if (compType.UniqueName.Equals("VPostProcessToneMapping")) { bEnable = checkBox_TM.Checked; } else if (compType.UniqueName.Equals("VPostProcessFXAA")) { bEnable = checkBox_AA.Checked; } else if (compType.UniqueName.Equals("VDeferredShadingLights")) { bEnable = checkBox_Lighting.Checked && radioButton_Deferred.Checked; } else if (compType.UniqueName.Equals("VDeferredShadingRimLight")) { bEnable = checkBox_RimLight.Checked && radioButton_Deferred.Checked; } else if (compType.UniqueName.Equals("VGlobalFogPostprocess")) { bEnable = checkBox_DepthFog.Checked && radioButton_Deferred.Checked; } ShapeComponent comp = (ShapeComponent)compType.CreateInstance(_scene.V3DLayer); comp.Active = bEnable; _scene.V3DLayer.RendererSetup._rendererComponents.Add(comp); } // Update renderer node EditorManager.RendererNodeManager.UpdateRendererNode(_scene.RendererProperties, _scene.Postprocessors); // Setup Lighting if (checkBox_TOD.Checked) { _scene.V3DLayer.EnableTimeOfDay = true; ShapeBase lightShape = null; DynLightShape sunlight = null; DynLightShape backlight = null; #if !HK_ANARCHY SunglareShape sunglare = null; #else Shape3D sunglare = null; #endif if (checkBox_Sunlight.Checked) { sunlight = new DynLightShape("Sun Light"); lightShape = sunlight; sunlight.LightType = LightSourceType_e.Directional; sunlight.Position = EditorManager.Scene.CurrentShapeSpawnPosition; sunlight.ExportAsStatic = false; sunlight.CastModelShadows = checkBox_Shadows.Checked; sunlight.CastWorldShadows = checkBox_Shadows.Checked; sunlight.MakeTimeOfDayLight(1.0f, true, null); } // Shadows if (checkBox_Shadows.Checked && checkBox_Sunlight.Checked) { #if !HK_ANARCHY ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VShadowMapComponentSunlight"); System.Diagnostics.Debug.Assert(compType != null, "Cannot create component of type VShadowMapComponentSunlight"); #else ShapeComponentType compType = (ShapeComponentType)EditorManager.EngineManager.ComponentClassManager.GetCollectionType("VMobileShadowMapComponentSpotDirectional"); System.Diagnostics.Debug.Assert(compType != null, "Cannot create component of type VMobileShadowMapComponentSpotDirectional"); #endif if (compType != null) { ShapeComponent comp = (ShapeComponent)compType.CreateInstance(sunlight); sunlight.AddComponentInternal(comp); } } // Back light if (checkBox_Backlight.Checked && checkBox_Sunlight.Checked) { backlight = new DynLightShape("Back Light"); backlight.LightType = LightSourceType_e.Directional; backlight.Position = EditorManager.Scene.CurrentShapeSpawnPosition; backlight.ExportAsStatic = false; backlight.CastModelShadows = false; backlight.CastWorldShadows = false; backlight.MakeTimeOfDayBackLight(); } #if !HK_ANARCHY // Sun glare if (checkBox_Sunglare.Checked && checkBox_Sunlight.Checked) { sunglare = new SunglareShape("Sun Glare"); sunglare.AttachToTimeOfDay = true; sunglare.Position = EditorManager.Scene.CurrentShapeSpawnPosition; } #endif // Group light shapes if (backlight != null || sunglare != null) { Group3DShape group = new Group3DShape("Sunlight Shapes"); group.Position = EditorManager.Scene.CurrentShapeSpawnPosition; group.AddChild(sunlight); if (backlight != null) { group.AddChild(backlight); } if (sunglare != null) { group.AddChild(sunglare); } lightShape = group; } // Add to scene if (lightShape != null) { _scene.V3DLayer.AddShape(lightShape, null); } } else { _scene.V3DLayer.EnableTimeOfDay = false; } }