public void SetModel(Urho.Model model) { _model.Model = model; var size = model.BoundingBox.Size; var center = model.BoundingBox.Center; CameraNode.Position = Vector3.Forward * size.Length * 3.0f + Vector3.Up * size.Y * 0.25f + center; //CameraNode.Position = new Vector3(size.X*1.0f, size.Y*1.0f, size.Z*0.5f)+center; CameraNode.LookAt(center, Vector3.Up); }
protected override void Start() { MonoDebugHud = new MonoDebugHud(this); MonoDebugHud.Show(); Input.MouseWheel += Input_MouseWheel; _lightType = LightType.Spot; _model = ResourceCache.GetModel("Models/MaterialGraphEditor/MaterialPreview.mdl", false); _animatedModel = false; }
private void LoadMDL(string mdl) { InvokeOnMain(() => { _model = ResourceCache.GetModel(mdl, false); _animatedModel = false; _animation = null; CreateSceneImpl(); SetupViewport(); }); }
private void LoadAnimatedMDL(string mdl, string animation) { InvokeOnMain(() => { _model = ResourceCache.GetModel(mdl, false); _animatedModel = true; if (string.IsNullOrWhiteSpace(animation)) { _animation = null; } else { _animation = ResourceCache.GetAnimation(animation, false); } CreateSceneImpl(); SetupViewport(); }); }
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 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); }
unsafe Model CreateModelFromVertexData(SurfaceDto surface) { var model = new Model(); var vertexBuffer = new VertexBuffer(Context, false); var indexBuffer = new IndexBuffer(Context, false); var geometry = new Geometry(); vertexBuffer.Shadowed = true; vertexBuffer.SetSize((uint)surface.VertexData.Length, ElementMask.Position | ElementMask.Normal | ElementMask.Color, false); fixed (SpatialVertexDto* p = &surface.VertexData[0]) vertexBuffer.SetData(p); var indexData = surface.IndexData; indexBuffer.Shadowed = true; indexBuffer.SetSize((uint)indexData.Length, false, false); indexBuffer.SetData(indexData); geometry.SetVertexBuffer(0, vertexBuffer); geometry.IndexBuffer = indexBuffer; geometry.SetDrawRange(PrimitiveType.TriangleList, 0, (uint)indexData.Length, 0, (uint)surface.VertexData.Length, true); model.NumGeometries = 1; model.SetGeometry(0, 0, geometry); model.BoundingBox = new BoundingBox(new Vector3(-1.26f, -1.26f, -1.26f), new Vector3(1.26f, 1.26f, 1.26f)); return model; }
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 } }