Beispiel #1
0
 public void AddNewSceneEntity(PrimitiveBase prim)
 {
     if (Engine.StartSceneState == null)
     {
         Engine.StartAction(ActionType.EntityCount);
         Engine.SceneEntities.Add(new SceneEntity(prim));
         Engine.EndAction();
         Engine.LastAddedPrimitive = prim;
     }
 }
Beispiel #2
0
        public SceneEntity(PrimitiveBase primitive)
        {
            _id = Engine.EntityCount++;

            _basicEffect = new BasicEffect(Engine.ActiveGraphicsDevice);
            _basicEffect.EnableDefaultLighting();

            _selectionBoxEffect = new BasicEffect(Engine.ActiveGraphicsDevice) { VertexColorEnabled = true };

            _vertexData = primitive.VertexData;
            _vertexPositions = primitive.VertexPositions;
            _primitiveType = primitive.PrimitiveType;
            _primitiveCount = primitive.PrimitiveCount;

            _controlVertices = new List<ControlVertex>();
            foreach (Vector3 vert in _vertexPositions)
            {
                _controlVertices.Add(new ControlVertex(vert));
            }

            _controlEdges = new List<ControlEdge>();
            foreach (Tuple<int, int> tuple in primitive.EdgeVertexIndexes)
            {
                _controlEdges.Add(new ControlEdge(_vertexPositions[tuple.Item1], _vertexPositions[tuple.Item2]));
            }

            _controlTriangles = new List<ControlTriangle>();
            foreach (Tuple<int, int, int> tuple in primitive.TriangleVertexIndexes)
            {
                _controlTriangles.Add(new ControlTriangle(_vertexPositions[tuple.Item1], _vertexPositions[tuple.Item2], _vertexPositions[tuple.Item3]));
            }

            if (primitive is Cylinder || primitive is Sphere)
            {
                var t = _vertexPositions.ToList();
                t.RemoveAt(0);
                _vertexPositions = t.ToArray();
                _controlVertices.RemoveAt(0);
            }

            RecalcCenter();
            RecalcBoundingBox();
        }