private ObjectBase CreateObjectCopy(ObjectBase selectedObject) { Cursor tmpCursor = Cursor.Current; Cursor = Cursors.WaitCursor; if (selectedObject.GetType().Equals(typeof(Engine.Mesh))) { var mesh = new Engine.Mesh(core, Settings, selectedObject.FileName); mesh.IsAnimated = (selectedObject as Engine.Mesh).IsAnimated; mesh.CustomTexture = (selectedObject as Engine.Mesh).CustomTexture; mesh.Visible = selectedObject.Visible; mesh.Position = selectedObject.Position; mesh.Rotation = selectedObject.Rotation; mesh.Scale = selectedObject.Scale; mesh.Mass = (selectedObject as Engine.Mesh).Mass; mesh.Bounding = (selectedObject as Engine.Mesh).Bounding; mesh.KineticFriction = (selectedObject as Engine.Mesh).KineticFriction; mesh.StaticFriction = (selectedObject as Engine.Mesh).StaticFriction; mesh.Bounciness = (selectedObject as Engine.Mesh).Bounciness; mesh.Softness = (selectedObject as Engine.Mesh).Softness; mesh.Material = (selectedObject as Engine.Mesh).Material; mesh.EnableLightning = (selectedObject as Engine.Mesh).EnableLightning; mesh.SetCustomCollection((selectedObject as Engine.Mesh).CustomParams); mesh.TextureScale = (selectedObject as Engine.Mesh).TextureScale; mesh.ScriptEnabled = (selectedObject as Engine.Mesh).ScriptEnabled; mesh.Script = (selectedObject as Engine.Mesh).Script.Replace((selectedObject as Engine.Mesh).Name, mesh.Name); mesh.Update(); AddToSceneTreeView(sceneObjectsNode, mesh); Cursor = tmpCursor; return mesh; } if (selectedObject.GetType().Equals(typeof(PointLight))) { VECTOR3D pos = selectedObject.Position; var pointLight = (PointLight)selectedObject; var light = new PointLight(core, new TV_3DVECTOR(pos.X, pos.Y, pos.Z)); light.Color = pointLight.Color; light.Radius = pointLight.Radius; light.Visible = pointLight.Visible; light.SetCustomCollection(pointLight.CustomParams); light.Update(); AddToSceneTreeView(sceneLightsNode, light); Cursor = tmpCursor; return light; } if (selectedObject.GetType().Equals(typeof(Sound))) { var sound = new Sound(core, selectedObject.FileName); sound.Position = selectedObject.Position; sound.Stopped = (selectedObject as Sound).Stopped; sound.Volume = (selectedObject as Sound).Volume; sound.Loop = (selectedObject as Sound).Loop; sound.Is3D = (selectedObject as Sound).Is3D; sound.SetCustomCollection((selectedObject as Sound).CustomParams); sound.Update(); AddToSceneTreeView(sceneSoundsNode, sound); Cursor = tmpCursor; return sound; } if (selectedObject.GetType().Equals(typeof(Engine.Trigger))) { var trigger = new Engine.Trigger(core); trigger.Position = selectedObject.Position; trigger.Rotation = selectedObject.Rotation; trigger.Scale = selectedObject.Scale; trigger.Color = (selectedObject as Trigger).Color; trigger.SetCustomCollection((selectedObject as Engine.Trigger).CustomParams); trigger.Update(); AddToSceneTreeView(sceneTriggersNode, trigger); Cursor = tmpCursor; return trigger; } if (selectedObject.GetType().Equals(typeof(Engine.Particle))) { var particle = new Engine.Particle(core, selectedObject.FileName); particle.Position = selectedObject.Position; particle.Rotation = selectedObject.Rotation; particle.Scale = selectedObject.Scale; particle.Visible = selectedObject.Visible; particle.SetCustomCollection((selectedObject as Engine.Particle).CustomParams); particle.Update(); AddToSceneTreeView(sceneParticlesNode, particle); Cursor = tmpCursor; return particle; } return null; }
private void tvObjects_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { Cursor = Cursors.WaitCursor; var type = Helpers.GetObjectType(e.Node.FullPath); var fullPath = Path.Combine(Application.StartupPath, e.Node.FullPath); var position = core.Camera.GetFrontPosition(10.0f); position.x = (float)Math.Round(position.x); position.y = (float)Math.Round(position.y); position.z = (float)Math.Round(position.z); bool skyBoxExists, skySphereExists = false; switch (type) { case Helpers.ObjectType.DirectionalLight: var sunId = -1; sunId = core.LightEngine.GetLightFromName(Helpers.SUN); if (sunId == -1) { var directionalLight = new DirectionalLight(core, position); directionalLight.Update(); selectedObject = directionalLight; AddToSceneTreeView(sceneLightsNode, directionalLight); } else { MessageBox.Show("There should be only one directional light.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case Helpers.ObjectType.PointLight: var pointLight = new PointLight(core, position); pointLight.Update(); selectedObject = pointLight; AddToSceneTreeView(sceneLightsNode, pointLight); break; case Helpers.ObjectType.SpotLight: MessageBox.Show("Not implemented.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case Helpers.ObjectType.StaticMesh: var mesh = new Engine.Mesh(core, Settings, fullPath) { Position = new VECTOR3D(position.x, position.y, position.z) }; mesh.Update(); selectedObject = mesh; AddToSceneTreeView(sceneObjectsNode, mesh); break; case Helpers.ObjectType.AnimatedMesh: var animatedMesh = new Engine.Mesh(core, Settings, fullPath) { Position = new VECTOR3D(position.x, position.y, position.z) }; animatedMesh.Update(); selectedObject = animatedMesh; AddToSceneTreeView(sceneObjectsNode, animatedMesh); break; case Helpers.ObjectType.Sound: var sound = new Sound(core, fullPath); sound.Update(); selectedObject = sound; AddToSceneTreeView(sceneSoundsNode, sound); break; case Helpers.ObjectType.SkyBox: skyBoxExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox)) == null ? false : true; if (skyBoxExists) break; skySphereExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere)) == null ? false : true; if (skySphereExists) { if (MessageBox.Show("This will remove existing sky sphere. Remove?", "Remove sky sphere?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { selectedObject = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere)); RemoveSelectedObject(); } else break; } var skyBox = new SkyBox(core); skyBox.Update(); AddToSceneTreeView(sceneSkyNode, skyBox); selectedObject = skyBox; break; case Helpers.ObjectType.SkySphere: skySphereExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere)) == null ? false : true; if (skySphereExists) break; skyBoxExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox)) == null ? false : true; if (skyBoxExists) { if (MessageBox.Show("This will remove existing sky box. Remove?", "Remove sky box?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { selectedObject = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox)); RemoveSelectedObject(); } else break; } var skySphere = new SkySphere(core); skySphere.Update(); AddToSceneTreeView(sceneSkyNode, skySphere); selectedObject = skySphere; break; case Helpers.ObjectType.Water: var water = new Water(core); selectedObject = water; AddToSceneTreeView(sceneWaterNode, water); break; case Helpers.ObjectType.Landscape: var landscape = new Landscape(core) { Position = new VECTOR3D(position.x, position.y, position.z) }; landscape.Update(); selectedObject = landscape; AddToSceneTreeView(sceneLandscapeNode, landscape); break; case Helpers.ObjectType.Trigger: var trigger = new Trigger(core) { Position = new VECTOR3D(position.x, position.y, position.z) }; trigger.Update(); selectedObject = trigger; AddToSceneTreeView(sceneTriggersNode, trigger); break; case Helpers.ObjectType.Particle: var particle = new Particle(core, fullPath); particle.Update(); selectedObject = particle; AddToSceneTreeView(sceneParticlesNode, particle); break; case Helpers.ObjectType.NotDetected: RunRegisteredExtension(fullPath); break; } propertyGrid.SelectedObject = selectedObject; Cursor = Cursors.Default; }