protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SubscribeToTickEvent(); if (EngineApp.Instance.ApplicationType != EngineApp.ApplicationTypes.ResourceEditor) { attached_mesh = this.AttachedObjects[0] as MapObjectAttachedMesh; if (attached_mesh == null) { Log.Error("CreatorRoads: Not found attached road mesh."); return; } else { mesh_name = this.Name; if (attached_mesh.MeshObject.Mesh.Save("Data\\" + mesh_name + ".mesh")) { attached_mesh.MeshName = mesh_name + ".mesh"; mesh = attached_mesh.MeshObject.Mesh; } } } }
/////////////// public MeshRayIntersectionOctreeManager( Mesh mesh ) { this.mesh = mesh; items = new Item[ mesh.SubMeshes.Length ]; for( int n = 0; n < items.Length; n++ ) { Item item = new Item( mesh.SubMeshes[ n ] ); items[ n ] = item; } }
public override void LoadContent() { this.cameraCB = new ConstantBuffer <PerFrameCB>(() => { return(new PerFrameCB(this.fpsCam.ViewMatrix * this.fpsCam.ProjectionMatrix, this.lightDirection, this.fpsCam.Position, this.orenNayarRoughness, (int)this.myDiffuse, (int)this.mySpecular, this.ColorObject)); }, 0, PipelineStages.VertexShader); Shader shader = new Shader(); shader.SetVertexShader("Lightning.hlsl", InputLayoutCreator.PosTexCoordNormal); shader.SetPixelShader("Lightning.hlsl"); Material material = new Material(shader); this.modelMesh = MeshLoader.LoadMesh(@"..\..\..\..\ProjectIglooSharpTestModels\Bunny\Bunny.obj", material); this.objectCB = new ConstantBuffer <PerObjectCB>(() => { return(new PerObjectCB(Matrix.Scaling(1.0f))); }, 1, PipelineStages.VertexShader); this.modelMesh.Material.ConstantBuffers.Add(this.objectCB); base.LoadContent(); }
void DestroyMesh() { if( mesh != null ) { mesh.Dispose(); mesh = null; } }
void CreateMesh() { Vec3 size = new Vec3( .97f, .97f, .1f ); Vec3[] positions; Vec3[] normals; int[] indices; GeometryGenerator.GenerateBox( size, out positions, out normals, out indices ); string meshName = MeshManager.Instance.GetUniqueName( string.Format( "JigsawPuzzlePiece[{0},{1}]", index.X, index.Y ) ); mesh = MeshManager.Instance.CreateManual( meshName ); //create submesh SubMesh subMesh = mesh.CreateSubMesh(); subMesh.UseSharedVertices = false; //init VertexData VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration; declaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position ); declaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal ); declaration.AddElement( 0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0 ); VertexBufferBinding bufferBinding = subMesh.VertexData.VertexBufferBinding; HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer( 32, positions.Length, HardwareBuffer.Usage.StaticWriteOnly ); bufferBinding.SetBinding( 0, vertexBuffer, true ); subMesh.VertexData.VertexCount = positions.Length; unsafe { Vertex* buffer = (Vertex*)vertexBuffer.Lock( HardwareBuffer.LockOptions.Normal ); for( int n = 0; n < positions.Length; n++ ) { Vertex vertex = new Vertex(); vertex.position = positions[ n ]; vertex.normal = normals[ n ]; if( JigsawPuzzleManager.Instance != null ) { Vec2I pieceCount = JigsawPuzzleManager.Instance.PieceCount; Vec2I i = index; if( vertex.position.X > 0 ) i.X++; if( vertex.position.Y > 0 ) i.Y++; vertex.texCoord = new Vec2( (float)i.X / (float)pieceCount.X, 1.0f - (float)i.Y / (float)pieceCount.Y ); } *buffer = vertex; buffer++; } vertexBuffer.Unlock(); } //calculate mesh bounds Bounds bounds = Bounds.Cleared; float radius = 0; foreach( Vec3 position in positions ) { bounds.Add( position ); float r = position.Length(); if( r > radius ) radius = r; } mesh.SetBoundsAndRadius( bounds, radius ); //init IndexData subMesh.IndexData = IndexData.CreateFromArray( indices, 0, indices.Length, false ); //init material subMesh.MaterialName = "JigsawPuzzleImage"; }
void CreateMesh() { string meshName = MeshManager.Instance.GetUniqueName( "DynamicMesh" ); mesh = MeshManager.Instance.CreateManual( meshName ); //set mesh gabarites Bounds bounds = new Bounds( new Vec3( -.1f, -.5f, -.5f ), new Vec3( .1f, .5f, .5f ) ); mesh.SetBoundsAndRadius( bounds, bounds.GetRadius() ); SubMesh subMesh = mesh.CreateSubMesh(); subMesh.UseSharedVertices = false; int maxVertices = ( Type.GridSize.X + 1 ) * ( Type.GridSize.Y + 1 ); int maxIndices = Type.GridSize.X * Type.GridSize.Y * 6; //init vertexData VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration; declaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position ); declaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal ); declaration.AddElement( 0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0 ); VertexBufferBinding bufferBinding = subMesh.VertexData.VertexBufferBinding; HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer( 32, maxVertices, HardwareBuffer.Usage.DynamicWriteOnly ); bufferBinding.SetBinding( 0, vertexBuffer, true ); //init indexData HardwareIndexBuffer indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer( HardwareIndexBuffer.IndexType._16Bit, maxIndices, HardwareBuffer.Usage.DynamicWriteOnly ); subMesh.IndexData.SetIndexBuffer( indexBuffer, true ); //set material subMesh.MaterialName = Type.MaterialName; needUpdateVertices = true; needUpdateIndices = true; }
private void DestroyGeometry() { if (collisionBody != null) { collisionBody.Dispose(); collisionBody = null; } if (sceneNode != null) { sceneNode.Dispose(); sceneNode = null; } if (meshObject != null) { meshObject.Dispose(); meshObject = null; } if (mesh != null) { mesh.Dispose(); mesh = null; } }
private unsafe void UpdateGeometry() { DestroyGeometry(); Curve positionCurve = GetPositionCurve(); Curve radiusCurve = null; { bool existsSpecialRadius = false; foreach (MapCurvePoint point in Points) { RenderableCurvePoint point2 = point as RenderableCurvePoint; if (point2 != null && point2.OverrideRadius >= 0) { existsSpecialRadius = true; break; } } if (existsSpecialRadius) { switch (radiusCurveType) { case RadiusCurveTypes.UniformCubicSpline: radiusCurve = new UniformCubicSpline(); break; case RadiusCurveTypes.Bezier: radiusCurve = new BezierCurve(); break; case RadiusCurveTypes.Line: radiusCurve = new LineCurve(); break; } for (int n = 0; n < Points.Count; n++) { MapCurvePoint point = Points[n]; if (!point.Editor_IsExcludedFromWorld()) { float rad = radius; RenderableCurvePoint renderableCurvePoint = point as RenderableCurvePoint; if (renderableCurvePoint != null && renderableCurvePoint.OverrideRadius >= 0) rad = renderableCurvePoint.OverrideRadius; radiusCurve.AddValue(point.Time, new Vec3(rad, 0, 0)); } } } } //create mesh Vertex[] vertices = null; int[] indices = null; if (positionCurve != null && positionCurve.Values.Count > 1 && Points.Count >= 2) { Vec3 positionOffset = -Position; int steps = (Points.Count - 1) * pathSteps + 1; int vertexCount = steps * (shapeSegments + 1); int indexCount = (steps - 1) * shapeSegments * 2 * 3; vertices = new Vertex[vertexCount]; indices = new int[indexCount]; //fill data { int currentVertex = 0; int currentIndex = 0; float currentDistance = 0; Vec3 lastPosition = Vec3.Zero; Quat lastRot = Quat.Identity; for (int nStep = 0; nStep < steps; nStep++) { int startStepVertexIndex = currentVertex; float coefficient = (float)nStep / (float)(steps - 1); Vec3 pos = CalculateCurvePointByCoefficient(coefficient) + positionOffset; Quat rot; { Vec3 v = CalculateCurvePointByCoefficient(coefficient + .3f / (float)(steps - 1)) - CalculateCurvePointByCoefficient(coefficient); if (v != Vec3.Zero) rot = Quat.FromDirectionZAxisUp(v.GetNormalize()); else rot = lastRot; } if (nStep != 0) currentDistance += (pos - lastPosition).Length(); float rad; if (radiusCurve != null) { Range range = new Range(radiusCurve.Times[0], radiusCurve.Times[radiusCurve.Times.Count - 1]); float t = range.Minimum + (range.Maximum - range.Minimum) * coefficient; rad = radiusCurve.CalculateValueByTime(t).X; } else rad = radius; for (int nSegment = 0; nSegment < shapeSegments + 1; nSegment++) { float rotateCoefficient = ((float)nSegment / (float)(shapeSegments)); float angle = rotateCoefficient * MathFunctions.PI * 2; Vec3 p = pos + rot * new Vec3(0, MathFunctions.Cos(angle) * rad, MathFunctions.Sin(angle) * rad); Vertex vertex = new Vertex(); vertex.position = p; Vec3 pp = p - pos; if (pp != Vec3.Zero) vertex.normal = pp.GetNormalize(); else vertex.normal = Vec3.XAxis; //vertex.normal = ( p - pos ).GetNormalize(); vertex.texCoord = new Vec2(currentDistance * textureCoordinatesTilesPerMeter, rotateCoefficient + .25f); vertex.tangent = new Vec4(rot.GetForward(), 1); vertices[currentVertex++] = vertex; } if (nStep < steps - 1) { for (int nSegment = 0; nSegment < shapeSegments; nSegment++) { indices[currentIndex++] = startStepVertexIndex + nSegment; indices[currentIndex++] = startStepVertexIndex + nSegment + 1; indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1; indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1; indices[currentIndex++] = startStepVertexIndex + nSegment + shapeSegments + 1; indices[currentIndex++] = startStepVertexIndex + nSegment; } } lastPosition = pos; lastRot = rot; } if (currentVertex != vertexCount) Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentVertex != vertexCount."); if (currentIndex != indexCount) Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentIndex != indexCount."); } if (vertices.Length != 0 && indices.Length != 0) { //create mesh string meshName = MeshManager.Instance.GetUniqueName( string.Format("__RenderableCurve_{0}_{1}", Name, uniqueMeshIdentifier)); uniqueMeshIdentifier++; //string meshName = MeshManager.Instance.GetUniqueName( string.Format( "__RenderableCurve_{0}", Name ) ); mesh = MeshManager.Instance.CreateManual(meshName); SubMesh subMesh = mesh.CreateSubMesh(); subMesh.UseSharedVertices = false; //init vertexData VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration; declaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); declaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); declaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0); declaration.AddElement(0, 32, VertexElementType.Float4, VertexElementSemantic.Tangent, 0); fixed (Vertex* pVertices = vertices) { subMesh.VertexData = VertexData.CreateFromArray(declaration, (IntPtr)pVertices, vertices.Length * Marshal.SizeOf(typeof(Vertex))); } subMesh.IndexData = IndexData.CreateFromArray(indices, 0, indices.Length, false); //set material subMesh.MaterialName = materialName; //set mesh gabarites Bounds bounds = Bounds.Cleared; foreach (Vertex vertex in vertices) bounds.Add(vertex.position); mesh.SetBoundsAndRadius(bounds, bounds.GetRadius()); } } //create MeshObject, SceneNode if (mesh != null) { meshObject = SceneManager.Instance.CreateMeshObject(mesh.Name); if (meshObject != null) { meshObject.SetMaterialNameForAllSubObjects(materialName); meshObject.CastShadows = true; sceneNode = new SceneNode(); sceneNode.Attach(meshObject); //apply offset sceneNode.Position = Position; MapObject.AssociateSceneNodeWithMapObject(sceneNode, this); } } //create collision body if (mesh != null && collision) { Vec3[] positions = new Vec3[vertices.Length]; for (int n = 0; n < vertices.Length; n++) positions[n] = vertices[n].position; string meshPhysicsMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry(positions, indices, null, MeshShape.MeshTypes.TriangleMesh, 0, 0); collisionBody = PhysicsWorld.Instance.CreateBody(); collisionBody.Static = true; collisionBody._InternalUserData = this; collisionBody.Position = Position; MeshShape shape = collisionBody.CreateMeshShape(); shape.MeshName = meshPhysicsMeshName; shape.MaterialName = CollisionMaterialName; shape.ContactGroup = (int)ContactGroup.Collision; //shape.VehicleDrivableSurface = collisionVehicleDrivableSurface; collisionBody.PushedToWorld = true; } needUpdate = false; }
void DestroyMesh() { if (mesh != null) { mesh.Dispose(); mesh = null; System.IO.File.Delete(Engine.FileSystem.VirtualFileSystem.GetRealPathByVirtual(attached_mesh.MeshName)); } }
void DestroyPlane() { DestroyReflectionTexture(); if( sceneNode != null ) { sceneNode.Dispose(); sceneNode = null; } if( meshObject != null ) { meshObject.Dispose(); meshObject = null; } if( meshPlane != null ) { meshPlane.Dispose(); meshPlane = null; } if( material != null ) { material.Dispose(); material = null; } }
void CreatePlane() { if( RenderSystem.Instance.IsDeviceLost() ) return; DestroyPlane(); Viewport defaultViewport = RendererWorld.Instance.DefaultViewport; if( RenderSystem.Instance.HasShaderModel2() && RenderSystem.Instance.Capabilities.UserClipPlanes && ReflectionLevel != ReflectionLevels.None ) { CreateReflectionTexture(); } string meshName = MeshManager.Instance.GetUniqueName( "WaterPlane" ); Vec2 tile; if( fixedPipelineMapTiling != 0 ) tile = size / fixedPipelineMapTiling; else tile = new Vec2( 0, 0 ); meshPlane = MeshManager.Instance.CreatePlane( meshName, new Plane( new Vec3( 0, 0, 1 ), 0 ), size, segments, true, 1, tile, new Vec3( 0, 1, 0 ) ); //create material string materialName = MaterialManager.Instance.GetUniqueName( "_GeneratedWaterPlane" ); material = (WaterPlaneHighLevelMaterial)HighLevelMaterialManager.Instance. CreateMaterial( materialName, "WaterPlaneHighLevelMaterial" ); material.Init( this ); material.UpdateBaseMaterial(); //change material of mesh foreach( SubMesh subMesh in meshPlane.SubMeshes ) subMesh.MaterialName = material.Name; meshObject = SceneManager.Instance.CreateMeshObject( meshName ); meshObject.RenderQueueGroup = renderQueueGroup; sceneNode = new SceneNode(); sceneNode.Attach( meshObject ); sceneNode.Position = position; sceneNode.Visible = Visible; needUpdatePlane = false; }
protected override void OnCreateScene( Mesh[] meshes, MeshObject[] meshObjects, Light[] lights, ColorValue shadowColor, bool calculateShadows ) { //create separated physics scene physicsScene = PhysicsWorld.Instance.CreateScene( "Static Lighting" ); //initialize contact group physicsScene.SpecialContactGroupsEnabled = true; physicsScene.SetupSpecialContactGroups( 1, 1, true ); Dictionary<Mesh, string> meshPhysicsMeshNames = new Dictionary<Mesh, string>(); //register physics custom mesh names foreach( Mesh mesh in meshes ) { string customMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry( mesh.Positions, mesh.Indices, null, MeshShape.MeshTypes.TriangleMesh, 0, 0 ); meshPhysicsMeshNames.Add( mesh, customMeshName ); } //create bodies foreach( MeshObject meshObject in meshObjects ) { Body body = physicsScene.CreateBody(); body.Static = true; body.Position = meshObject.Position; body.Rotation = meshObject.Rotation; body.UserData = meshObject; MeshShape shape = body.CreateMeshShape(); shape.ContactGroup = contactGroup; shape.MeshName = meshPhysicsMeshNames[ meshObject.Mesh ]; shape.MeshScale = meshObject.Scale; body.PushedToWorld = true; } //lights { this.lights = new MyLight[ lights.Length ]; for( int n = 0; n < lights.Length; n++ ) { Light light = lights[ n ]; MyLight myLight = null; PointLight pointLight = light as PointLight; if( pointLight != null ) myLight = new MyPointLight( pointLight ); SpotLight spotLight = light as SpotLight; if( spotLight != null ) myLight = new MySpotLight( spotLight ); DirectionalLight directionalLight = light as DirectionalLight; if( directionalLight != null ) myLight = new MyDirectionalLight( directionalLight ); if( myLight == null ) Log.Fatal( "SimpleStaticLightingCalculationWorld.OnCreateScene: not implemented light type." ); this.lights[ n ] = myLight; this.lights[ n ].Initialize(); } } this.shadowColor = shadowColor; this.calculateShadows = calculateShadows; }
void CreatePlane() { DestroyPlane(); string meshName; if( !string.IsNullOrEmpty( customMesh ) ) { meshName = customMesh; } else { meshName = MeshManager.Instance.GetUniqueName( "WaterPlane" ); Vec2 tile; if( fixedPipelineMapTiling != 0 ) tile = size / fixedPipelineMapTiling; else tile = new Vec2( 0, 0 ); meshPlane = MeshManager.Instance.CreatePlane( meshName, new Plane( new Vec3( 0, 0, 1 ), 0 ), size, segments, true, 1, tile, new Vec3( 0, 1, 0 ) ); } //create material string materialName = MaterialManager.Instance.GetUniqueName( "_GeneratedWaterPlane" ); material = (WaterPlaneHighLevelMaterial)HighLevelMaterialManager.Instance. CreateMaterial( materialName, "WaterPlaneHighLevelMaterial" ); material.Init( this ); material.UpdateBaseMaterial(); meshObject = SceneManager.Instance.CreateMeshObject( meshName ); if( meshObject != null ) { meshObject.SetMaterialNameForAllSubObjects( material.Name ); meshObject.RenderQueueGroup = renderQueueGroup; sceneNode = new SceneNode(); sceneNode.Position = position; sceneNode.Visible = Visible; sceneNode.AllowSceneManagementCulling = false; sceneNode.Attach( meshObject ); } needUpdatePlane = false; }
private void CreateMesh() { DetachMeshFromEntity(); DestroyMesh(); int maxVertexCount = tesselation * tesselation; int maxIndexCount = (tesselation - 1) * (tesselation - 1) * 6; string meshName = MeshManager.Instance.GetUniqueName("DynamicSinusoidSurface"); mesh = MeshManager.Instance.CreateManual(meshName); SubMesh subMesh = mesh.CreateSubMesh(); subMesh.UseSharedVertices = false; //init vertexData VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration; declaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); declaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); declaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0); //declaration.AddElement( 0, 32, VertexElementType.Float4, VertexElementSemantic.Tangent, 0 ); HardwareBuffer.Usage usage = HardwareBuffer.Usage.DynamicWriteOnly;//HardwareBuffer.Usage.StaticWriteOnly; HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer( Marshal.SizeOf(typeof(Vertex)), maxVertexCount, usage); subMesh.VertexData.VertexBufferBinding.SetBinding(0, vertexBuffer, true); subMesh.VertexData.VertexCount = maxVertexCount; HardwareIndexBuffer indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer( HardwareIndexBuffer.IndexType._16Bit, maxIndexCount, usage); subMesh.IndexData.SetIndexBuffer(indexBuffer, true); subMesh.IndexData.IndexCount = maxIndexCount; //set material subMesh.MaterialName = "DynamicSinusoidSurface"; //set mesh gabarites Bounds bounds = new Bounds(-Scale / 2, Scale / 2); mesh.SetBoundsAndRadius(bounds, bounds.GetRadius()); }
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; }