public override ShapeBase CreateShapeInstance() { string ShapeName = System.IO.Path.GetFileNameWithoutExtension(_MeshPath); if (ShapeName == string.Empty) ShapeName = "Model"; StaticMeshShape SMS = new StaticMeshShape(ShapeName); SMS.MeshFileName = _MeshPath; return SMS; }
/// <summary> /// Overridden function that performs a "relevant operation" /// </summary> /// <param name="name"></param> /// <param name="iShapeIndex"></param> /// <param name="iShapeCount"></param> public override void PerformRelevantOperation(string name, int iShapeIndex, int iShapeCount) { base.PerformRelevantOperation (name, iShapeIndex, iShapeCount); if ([email protected]"Set lightgrid offset\pivot" || [email protected]"Set lightgrid offset\box center" || [email protected]"Set lightgrid offset\box bottom") { // open a group action if (iShapeIndex==0) EditorManager.Actions.StartGroup("light grid : "+name); Vector3F vNewOfs = Vector3F.Zero; if (name == @"Set lightgrid offset\pivot") vNewOfs = Vector3F.Zero; else if ([email protected]"Set lightgrid offset\box center") { BoundingBox bbox = LocalScaledBoundingBox; if (bbox.Valid) vNewOfs = bbox.Center; } else if ([email protected]"Set lightgrid offset\box bottom") { BoundingBox bbox = LocalScaledBoundingBox; if (bbox.Valid) { vNewOfs = bbox.Center; vNewOfs.Z = bbox.vMin.Z; } } // set the offset EditorManager.Actions.Add(SetPropertyAction.CreateSetPropertyAction(this,"LightGridSampleOfs",vNewOfs)); // close group action if (iShapeIndex==iShapeCount-1) EditorManager.Actions.EndGroup(); return; } if ([email protected]"Shaders\Model surfaces") { if (ShaderAssignment!=null) ShaderAssignment(this,new ShaderAssignmentEventArgs(this)); return; } if (name == RO_CONVERT_TO_STATIC_MESH) { if (iShapeCount > 1 && iShapeIndex == 0) EditorManager.Actions.StartGroup("Convert entities to meshes"); // create a shape with the same relevant properties StaticMeshShape replacement = new StaticMeshShape(this.ShapeName); // remap all public browsable properties (except uniform scaling as this overwrites current scaling) StringCollection exclude = new StringCollection(); exclude.Add("UniformScaling"); SerializationHelper.CopyInstanceProperties(replacement, this, true,true,exclude); string sVMeshPath = this.ModelFile; // remap file name of the mesh if (!string.IsNullOrEmpty(sVMeshPath)) replacement.MeshFileName = Path.ChangeExtension(sVMeshPath, ".vmesh"); EditorManager.Actions.Add(new ReplaceShapeAction(this, replacement)); if (iShapeCount > 1 && iShapeIndex == iShapeCount - 1) EditorManager.Actions.EndGroup(); return; } if (name == RO_OPEN_IN_MV) { OpenModelInModelViewer(); return; } }
void EditorManager_SceneEvent(object sender, SceneEventArgs e) { if (e.action == SceneEventArgs.Action.AllowExport) { if (MeshExportSettings.AutomaticExport && MeshExportSettings.ExportForAssetProfile.IsActiveProfileSet) { if (EditorManager.ShowMessageBox("The terrain data needs to be saved before the export.\n Continue?", "Save Terrain Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { if (e is ExportSceneEventArgs) { ((ExportSceneEventArgs)e).CancelExport = true; } } } } else if (e.action == SceneEventArgs.Action.BeforeExport && HasEngineInstance()) { if (e is ExportSceneEventArgs) { if (MeshExportSettings.ExportForAssetProfile.IsActiveProfileSet) { if (!MeshExportSettings.AutomaticExport) return; EditorManager.ActiveView.SetDefaultContext(); int iCountX = 0; int iCountY = 0; if (!EngineTerrain.GetSectorMeshCount(ref iCountX, ref iCountY)) return; EditorManager.EngineManager.DisableRendering(); EditorManager.Progress.ShowProgressDialog("Exporting terrain sectors as static meshes"); try { // export each sector of the terrain as a .vmesh file EngineTerrain.ExportTerrainMeshs(MeshExportSettings, EditorManager.Progress, 50.0f, false); // collection which holds all exported zones, these zones are removed after the export (see below: SceneEventArgs.Action.AfterExport) exportedZones = new ZoneCollection(); // disable visibility zone disconnecting EngineTerrain.SetTerrainMeshExportFlag(true); float fStep = 50.0f / (float)(iCountX*iCountY); float fPercentage = 50.0f; // create zone, layer, and static mesh for each sector of the terrain for (int sy = 0; sy < iCountY; ++sy) { for (int sx = 0; sx < iCountX; ++sx) { string sectorFileName = EngineTerrain.GetSectorMeshFileName(sx, sy); if (sectorFileName == null) continue; // create static mesh StaticMeshShape shape = new StaticMeshShape(Path.GetFileNameWithoutExtension(sectorFileName)); shape.Position = (Vector3F)EngineTerrain.GetSectorOrigin(sx, sy); shape.MeshFileName = sectorFileName; string lightmapFileName = EngineTerrain.GetSectorLightmapName(sx, sy); if (lightmapFileName != null) shape.CustomLightmap = lightmapFileName; // create zone string uniqueFileName = FileHelper.CreateUniqueFilename(EditorManager.Scene.LayerDirectoryName, "TerrainSectorZone" + sx + "_" + sy, IScene.ZoneFileExtension); object[] zoneParameters = { EditorManager.Scene.CreateUniqueZoneName("TerrainSectorZone" + sx + "_" + sy) }; Zone zone = EditorManager.ZoneFactory.CreateInstance(zoneParameters); zone.SetZoneFileNameInternal(uniqueFileName); zone.LoadedDistance = MeshExportSettings.LoadedDistance; zone.CacheInMargin = MeshExportSettings.CacheInMargin; zone.CacheOutMargin = MeshExportSettings.CacheOutMargin; EditorManager.Scene.AddZone(zone); // create layer string uniqueFile = EditorManager.Scene.Layers.CreateUniqueLayerFileName(EditorManager.Scene.LayerDirectoryName, "TerrainSector" + sx + "_" + sy); object[] layerParameters = { "TerrainSector" }; Layer layer = EditorManager.LayerFactory.CreateInstance(layerParameters); layer.SetLayerFileNameInternal(uniqueFile); layer.AttachToZone(zone); EditorManager.Scene.AddLayer(layer, true); layer.AddShape(shape, shape.Parent); // add zone to export info, so that it gets exported ((ExportSceneEventArgs)e).ExportInfo.RelevantExportZones.Add(zone); ((ExportSceneEventArgs)e).ExportInfo.RelevantEmbeddedZones.Add(zone); // keep reference to be able to remove the zone after export exportedZones.Add(zone); fPercentage += fStep; if (EditorManager.Progress != null) EditorManager.Progress.Percentage = fPercentage; Application.DoEvents(); } } } finally { EditorManager.Progress.HideProgressDialog(); EditorManager.EngineManager.EnableRendering(); } } } } else if (e.action == SceneEventArgs.Action.AfterExport && HasEngineInstance()) { if (e is ExportSceneEventArgs) { if (MeshExportSettings.ExportForAssetProfile.IsActiveProfileSet) { if (!MeshExportSettings.AutomaticExport) return; // re-enable default behaviour for terrain visibility zone serialization EngineTerrain.SetTerrainMeshExportFlag(false); foreach (Zone zone in exportedZones) { // create .deleted filenames string absLayerFileName = zone.Layers[0].AbsoluteLayerFilename + ".deleted"; string absZoneFileName = zone.AbsoluteZoneFilename + ".deleted"; EditorManager.Scene.RemoveZone(zone); // delete .deleted files, because they are not needed in any way if (File.Exists(absLayerFileName)) File.Delete(absLayerFileName); if (File.Exists(absZoneFileName)) File.Delete(absZoneFileName); } exportedZones.Clear(); } } } }
private void createShape(System.Windows.Forms.DragEventArgs e) { _assetPaths = CSharpFramework.Contexts.IDropContext.GetAssetPaths(e); _assetTypes = CSharpFramework.Contexts.IDropContext.GetAssetTypes(e); _assetNames = CSharpFramework.Contexts.IDropContext.GetAssetNames(e); Debug.Assert(_assetPaths.Length == _assetTypes.Length && _assetPaths.Length == _assetNames.Length); if (_assetPaths.Length == 0) return; if (_assetTypes[0] == "Model") { EntityShape entity = new EntityShape(_assetNames[0]); entity.EntityClass = "VisBaseEntity_cl"; entity.ModelFile = _assetPaths[0]; _dummyShape = entity; } else if (_assetTypes[0] == "StaticMesh") { StaticMeshShape staticMesh = new StaticMeshShape(_assetNames[0]); staticMesh.MeshFileName = _assetPaths[0]; _dummyShape = staticMesh; } else if (_assetTypes[0] == "Prefab") { PrefabShape prefabShape = new PrefabShape(_assetNames[0]); prefabShape.Filename = _assetPaths[0]; _dummyShape = prefabShape; } }
void EditorManager_ProcessExternalFileDrop(object sender, ExternalFileDropArgs e) { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return; if (EditorManager.Scene == null) return; string filename = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; if (!EditorManager.Project.CheckRelative(filename)) { EditorManager.ShowMessageBox("Cannot drop file \n\n" + filename + "\n\n because it is not project relative", "Cannot drop object", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } filename = EditorManager.Project.MakeRelative(filename); string extension = Path.GetExtension(filename); string name = Path.GetFileNameWithoutExtension(filename); if (string.Compare(extension, ".model", true) == 0) { EntityShape shape = new EntityShape(name); shape.ModelFile = filename; EditorManager.ActiveView.DropObject(shape, e); } else if (string.Compare(extension, ".vmesh", true) == 0) { StaticMeshShape shape = new StaticMeshShape(name); shape.MeshFileName = filename; EditorManager.ActiveView.DropObject(shape, e); } else if (string.Compare(extension, ".prefab", true) == 0) { PrefabShape shape = new PrefabShape(name); shape.Filename = filename; EditorManager.ActiveView.DropObject(shape, e); } }