public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent <StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent <StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; if (isNew) { staticModel.SetMaterial(this.spatialMaterial); var collisionShape = node.CreateComponent <CollisionShape>(); collisionShape.SetTriangleMesh(generatedModel, 0, Vector3.One, Vector3.Zero, Quaternion.Identity); var rigidBoy = node.CreateComponent <RigidBody>(); rigidBoy.Mass = 0; } }
public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent <StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent <StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; if (isNew) { staticModel.SetMaterial(spatialMaterial); node.CreateComponent <Obstacle>(); } else { //Update Collision shape } }
public override unsafe void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent <StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent <StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; if (isNew) { staticModel.SetMaterial(material); } var surfaceDto = new SurfaceDto { Id = surface.SurfaceId, IndexData = surface.IndexData, BoundsCenter = new Vector3Dto(surface.BoundsCenter.X, surface.BoundsCenter.Y, surface.BoundsCenter.Z), BoundsOrientation = new Vector4Dto(surface.BoundsRotation.X, surface.BoundsRotation.Y, surface.BoundsRotation.Z, surface.BoundsRotation.W), BoundsExtents = new Vector3Dto(surface.Extents.X, surface.Extents.Y, surface.Extents.Z) }; var vertexData = surface.VertexData; surfaceDto.VertexData = new SpatialVertexDto[vertexData.Length]; for (int i = 0; i < vertexData.Length; i++) { SpatialVertex vertexItem = vertexData[i]; surfaceDto.VertexData[i] = *(SpatialVertexDto *)(void *)&vertexItem; } clientConnection.SendObject(surfaceDto.Id, surfaceDto); }
public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent <StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent <StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; Material mat; Color startColor; Color endColor = new Color(0.8f, 0.8f, 0.8f); if (isNew) { startColor = Color.Blue; mat = Material.FromColor(endColor); staticModel.SetMaterial(mat); } else { startColor = Color.Red; mat = staticModel.GetMaterial(0); } mat.FillMode = wireframe ? FillMode.Wireframe : FillMode.Solid; var specColorAnimation = new ValueAnimation(); specColorAnimation.SetKeyFrame(0.0f, startColor); specColorAnimation.SetKeyFrame(1.5f, endColor); mat.SetShaderParameterAnimation("MatDiffColor", specColorAnimation, WrapMode.Once, 1.0f); }
public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent<StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent<StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; Material mat; Color startColor; Color endColor = new Color(0.8f, 0.8f, 0.8f); if (isNew) { startColor = Color.Blue; mat = Material.FromColor(endColor); staticModel.SetMaterial(mat); } else { startColor = Color.Red; mat = staticModel.GetMaterial(0); } mat.FillMode = wireframe ? FillMode.Wireframe : FillMode.Solid; var specColorAnimation = new ValueAnimation(); specColorAnimation.SetKeyFrame(0.0f, startColor); specColorAnimation.SetKeyFrame(1.5f, endColor); mat.SetShaderParameterAnimation("MatDiffColor", specColorAnimation, WrapMode.Once, 1.0f); }
//################################################################################################################### public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { // create a node for spatial mapping if not exist Node node = this.Scene.GetChild(surface.SurfaceId, false); if (node == null) { node = this.Scene.CreateChild(surface.SurfaceId); } // add the spatial map to the node StaticModel staticModel = node.CreateComponent <StaticModel>(); staticModel.Model = generatedModel; // set position and orientation of the map according to the world scene node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; // stop spatial mapping to avoid slowness StopSpatialMapping(); }
public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { StaticModel model; // If the surface already exists get its node otherwise creates a new one var node = _detectedSurfaceNode.GetChild(surface.SurfaceId, false); if (node != null) { model = node.GetComponent <StaticModel>(); } else { node = _detectedSurfaceNode.CreateChild(surface.SurfaceId); model = node.CreateComponent <StaticModel>(); } // Set the position and rotation node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; // The model is created with the vertex data model.Model = CreateModelFromVertexData(surface.VertexData, surface.IndexData); // Add a rigidbody for the physic engine node.CreateComponent <RigidBody>(); // Add a collision shape based on the model var shape = node.CreateComponent <CollisionShape>(); shape.SetTriangleMesh(model.Model, 0, Vector3.One, Vector3.Zero, Quaternion.Identity); // Add a material for our model (a green wireframe) var material = Material.FromColor(Color.Green); material.FillMode = FillMode.Wireframe; model.SetMaterial(material); }
public override unsafe void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent<StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent<StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; if (isNew) { staticModel.SetMaterial(material); } var surfaceDto = new SurfaceDto { Id = surface.SurfaceId, IndexData = surface.IndexData, BoundsCenter = new Vector3Dto(surface.BoundsCenter.X, surface.BoundsCenter.Y, surface.BoundsCenter.Z), BoundsOrientation = new Vector4Dto(surface.BoundsRotation.X, surface.BoundsRotation.Y, surface.BoundsRotation.Z, surface.BoundsRotation.W), BoundsExtents = new Vector3Dto(surface.Extents.X, surface.Extents.Y, surface.Extents.Z) }; var vertexData = surface.VertexData; surfaceDto.VertexData = new SpatialVertexDto[vertexData.Length]; for (int i = 0; i < vertexData.Length; i++) { SpatialVertex vertexItem = vertexData[i]; surfaceDto.VertexData[i] = *(SpatialVertexDto*)(void*)&vertexItem; } clientConnection.SendObject(surfaceDto.Id, surfaceDto); }
public override Model GenerateModelFromSpatialSurface(SpatialMeshInfo surface) { return(CreateModelFromVertexData(surface.VertexData, surface.IndexData)); }
public override void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel) { bool isNew = false; StaticModel staticModel = null; Node node = environmentNode.GetChild(surface.SurfaceId, false); if (node != null) { isNew = false; staticModel = node.GetComponent<StaticModel>(); } else { isNew = true; node = environmentNode.CreateChild(surface.SurfaceId); staticModel = node.CreateComponent<StaticModel>(); } node.Position = surface.BoundsCenter; node.Rotation = surface.BoundsRotation; staticModel.Model = generatedModel; if (isNew) { staticModel.SetMaterial(spatialMaterial); var rigidBody = node.CreateComponent<RigidBody>(); rigidBody.RollingFriction = 0.5f; rigidBody.Friction = 0.5f; var collisionShape = node.CreateComponent<CollisionShape>(); collisionShape.SetTriangleMesh(generatedModel, 0, Vector3.One, Vector3.Zero, Quaternion.Identity); } else { //Update Collision shape } }