Beispiel #1
0
        protected override void OnInit()
        {
            base.OnInit();

            _mesh         = new Mesh();
            _mesh.Type    = PrimitiveType.Lines;
            _mesh.Indices = new UInt32[] {
                0, 1,
                1, 2,
                2, 3,
                3, 0,
                4, 5,
                5, 6,
                6, 7,
                7, 4,
                0, 4,
                1, 5,
                2, 6,
                3, 7
            };

            _renderer                = SceneObject.AddComponent <MeshRenderable>();
            _renderer.Material       = new Material(MaterialType.FlatColor);
            _renderer.Material.Color = Vector4.One;
            _renderer.IsRaytracable  = false;
            _renderer.IsEnabled      = false;
        }
Beispiel #2
0
        private void AddCones()
        {
            const float ConeWidth  = 0.05f;
            const float ConeLength = 0.20f;

            _arrowRenderer          = SceneObject.AddComponent <MeshRenderable>();
            _arrowRenderer.Material = _material;

            var xCone = Cone.Create(ConeWidth, ConeLength, 6);

            xCone.Transform(new Matrix(new Vector3(1 - ConeLength, 0, 0), new Quaternion(Vector3.Forward, MathF.PI / 2), Vector3.One));
            _coneVertexCount = xCone.Vertices.Length;

            var yCone = Cone.Create(ConeWidth, ConeLength, 6);

            yCone.Transform(new Matrix(new Vector3(0, 1 - ConeLength, 0), Quaternion.Identity, Vector3.One));

            var zCone = Cone.Create(ConeWidth, ConeLength, 6);

            zCone.Transform(new Matrix(new Vector3(0, 0, 1 - ConeLength), new Quaternion(Vector3.Right, MathF.PI / 2), Vector3.One));

            _arrowMesh = CompoundMesh.Create(xCone, yCone);
            _arrowMesh = CompoundMesh.Create(_arrowMesh, zCone);

            _arrowMesh.CalculateBounds();
            _arrowRenderer.Mesh = _arrowMesh;
        }
Beispiel #3
0
        public void Select(MeshRenderable renderer)
        {
            _boundingBox.SetTarget(renderer);

            if (Selected != null)
            {
                Selected(renderer);
            }
        }
Beispiel #4
0
 private void ObjectSelected(MeshRenderable renderer)
 {
     if (renderer == null)
     {
         _target = null;
         _pickerRenderer.IsEnabled = false;
     }
     else
     {
         _target = renderer.Transform;
         this.Transform.WorldPosition = _target.WorldPosition;
         _pickerRenderer.IsEnabled    = true;
     }
 }
Beispiel #5
0
        public void SetTarget(MeshRenderable target)
        {
            if (IsDisposed)
            {
                Log.Error("object disposed");
                return;
            }

            if (target == null)
            {
                _renderer.IsEnabled = false;
                return;
            }
            if (target.Mesh == null)
            {
                _renderer.IsEnabled = false;
                return;
            }
            if (target.Mesh.Bounds == null)
            {
                _renderer.IsEnabled = false;
                return;
            }

            _target = target;

            var size     = target.Mesh.Bounds.Size / 2;
            var vertices = new Vector3[] {
                new Vector3(-1, -1, -1) * size,
                new Vector3(-1, 1, -1) * size,
                new Vector3(1, 1, -1) * size,
                new Vector3(1, -1, -1) * size,

                new Vector3(-1, -1, 1) * size,
                new Vector3(-1, 1, 1) * size,
                new Vector3(1, 1, 1) * size,
                new Vector3(1, -1, 1) * size
            };

            _mesh.Vertices = vertices;

            _renderer.Mesh = _mesh;
            _renderer.UpdateMesh();
            _renderer.IsEnabled = true;

            Update();
        }
Beispiel #6
0
        public void Select(Node sceneObject)
        {
            if (IsDisposed)
            {
                Log.Error("object disposed");
                return;
            }

            MeshRenderable renderer = null;

            if (sceneObject != null)
            {
                renderer = sceneObject.GetComponent <MeshRenderable>();
            }

            Select(renderer);
        }
Beispiel #7
0
        protected override void OnInit()
        {
            base.OnInit();

            _material = new Material(MaterialType.FlatVertexColor);

            var frag = @"
void getFragment(inout fragment_info fragment) {
    fragment.normal = frag_in.normal;

	if(dot(normalize(fragment.normal), normalize(-frag_in.view_pos)) > -0.25)
		fragment.emission = frag_in.color.xyz;
	else
		fragment.emission = vec3(0.75, 0.75, 0.75);
    fragment.albedo = vec4(0.0, 0.0, 0.0, 1.0);
}
";

            _renderer          = SceneObject.AddComponent <MeshRenderable>();
            _renderer.Material = new Material(null, frag, RenderQueue.Opaque);

            var circle = Ellipse.Create(Quaternion.Identity, Vector2.One * Radius, CircleSegmentCount);

            var meshBuilder = new MeshBuilder();

            meshBuilder.AddMesh(circle);
            meshBuilder.AddMesh(circle, Quaternion.CreateFromYawPitchRoll(0, MathF.PIOver2, 0));
            meshBuilder.AddMesh(circle, Quaternion.CreateFromYawPitchRoll(MathF.PIOver2, 0, 0));

            var mesh = meshBuilder.GetMesh();

            mesh.DrawStyle = PolygonMode.Line;
            mesh.Type      = PrimitiveType.Lines;
            mesh.Colors    = new Vector3Buffer(CircleSegmentCount * 3);
            _renderer.Mesh = mesh;

            RestoreColors();

            _sphere = new Sphere(Vector3.Zero, Radius);
            _xPlane = new Plane(new Vector3(1, 0, 0), 0);
            _yPlane = new Plane(new Vector3(0, 1, 0), 0);
            _zPlane = new Plane(new Vector3(0, 0, 1), 0);
        }
Beispiel #8
0
        protected override void OnStart()
        {
            base.OnStart();

            _collider        = this.SceneObject.AddComponent <SphereCollider>();
            _collider.Radius = 0.1f;

            _pickerRenderer                = this.SceneObject.AddComponent <MeshRenderable>();
            _pickerRenderer.Mesh           = Icosahedron.Create(0.02f, 1);
            _pickerRenderer.IsEnabled      = false;
            _pickerRenderer.Material       = new Material(MaterialType.FlatColor);
            _pickerRenderer.Material.Color = new Vector4(1, 1, 0, 1);
            _pickerRenderer.IsRaytracable  = false;

            _selector = SceneObject.GetComponent <ObjectSelector>();
            if (_selector != null)
            {
                _selector.Selected += ObjectSelected;
            }
        }
Beispiel #9
0
        private void Control_MouseDown(object sender, MouseEventArgs e)
        {
            if (_boundingBox == null)
            {
                return;
            }

            if ((_control.PressedMouseButtons & MouseButtons.Left) != MouseButtons.Left)
            {
                return;
            }

            var            ray      = _camera.Unproject(_control.ScreenMousePosition);
            var            hit      = _control.Scene.RaycastMeshes(ray);
            MeshRenderable renderer = null;

            if (hit != null)
            {
                renderer = hit.Renderer;
            }
            Select(renderer);
        }
Beispiel #10
0
        protected override void OnStart()
        {
            _control = Scene.Control;

            _control.MouseDown += Control_MouseDown;

            var material = new Material(MaterialType.FlatColor);

            material.Color      = new Vector4(1, 1, 0, 1);
            _renderer           = SceneObject.AddComponent <MeshRenderable>();
            _renderer.Material  = material;
            _renderer.IsEnabled = false;

            var mesh    = new Mesh();
            var buffer3 = new Vector3Buffer(2);

            buffer3.Usage = BufferUsage.DynamicDraw;
            mesh.Vertices = buffer3;
            mesh.Type     = PrimitiveType.Lines;

            _renderer.Mesh = mesh;

            var hitPointSo = new Node(Scene);
            var sphere     = Icosahedron.Create(0.01f, 1);

            _hitPointRenderer                   = hitPointSo.AddComponent <MeshRenderable>();
            _hitPointRenderer.IsEnabled         = false;
            _hitPointRenderer.Mesh              = sphere;
            _hitPointRenderer.SceneObject.Layer = 2;
            _hitPointRenderer.Material          = material;

            _hitPointTransform = hitPointSo.Transform;

            _selectedMaterial       = new Material(MaterialType.DiffuseColor);
            _selectedMaterial.Color = new Vector4(1, 0, 0, 1);
        }