Пример #1
0
 public void DetachGeometry(Geometry3D Geometry)
 {
     if (Geometries.ContainsKey(Geometry))
     {
         Geometries.Remove(Geometry);
         Count = Geometries.Count;
     }
 }
Пример #2
0
 public void Attach(Geometry3D Geometry)
 {
     if (!Geometries.ContainsKey(Geometry))
     {
         Geometries.Add(Geometry, Geometry.Name);
         Count = Geometries.Count;
     }
 }
Пример #3
0
        /*
         * public void AttachRange(List<Node3D> NodeList)
         * {
         *  for (int i = 0; i < NodeList.Count; i++)
         *  {
         *      if (!Children.ContainsKey(NodeList[i]))
         *      {
         *          Children.Add(NodeList[i], NodeList[i].Name);
         *      }
         *  }
         * }
         */

        public void AttachRange(List <Geometry3D> GeometryList)
        {
            for (int i = 0; i < GeometryList.Count; i++)
            {
                if (!Geometries.ContainsKey(GeometryList[i]))
                {
                    Geometries.Add(GeometryList[i], GeometryList[i].Name);
                }
            }
            Count = Geometries.Count;
        }
Пример #4
0
 public bool HasGeometry(Geometry3D Geometry)
 {
     return(Geometries.ContainsKey(Geometry));
 }
Пример #5
0
        /// <summary>
        /// Generates a shape
        /// </summary>
        /// <param name="name">Name of the geometry</param>
        /// <returns>Returns an handle to the shape or null</returns>
        public Mesh GenerateShape(string name)
        {
            if (string.IsNullOrEmpty(name) || !Geometries.ContainsKey(name))
            {
                return(null);
            }

            Mesh shape = new Mesh();

            // Get the geometry
            Geometry geometry = Geometries[name];
            MeshDef  mesh     = geometry.Mesh;



            // Get the size of one element (sum of all strides)
            int stridesum = 0;

            foreach (Source src in mesh.Sources.Values)
            {
                stridesum += src.Technique.Accessor.Stride;
            }



            // Create the index buffer
            int indexCount = mesh.Triangles.Count * 3;

            int[] indexbuffer = new int[indexCount];
            //for (int i = 0; i < indexbuffer.Length; i++)
            //   indexbuffer[i] = -1;

            // Create the array buffer
            float[] buffer = new float[stridesum * mesh.VertexCount];
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = 99.0f;
            }



            // Offset in the <p> buffer according to <inputs> strides
            int offset = mesh.Triangles.GetInput(InputSemantic.Vertex).Offset;

            // For each index in the <p> tag
            for (int i = 0; i < indexCount; i++)
            {
                // Position in the <p> tag
                int pos = i * mesh.Triangles.Inputs.Count + offset;

                // Fill the index buffer
                indexbuffer[i] = mesh.Triangles.Data[pos];
            }



            // Copy all vertices to the array buffer
            Source source = mesh.GetVerticesSource();

            for (int i = 0; i < source.Technique.Accessor.Count; i++)
            {
                buffer[i * stridesum]     = source.Array.Data[i * 3];
                buffer[i * stridesum + 1] = source.Array.Data[i * 3 + 1];
                buffer[i * stridesum + 2] = source.Array.Data[i * 3 + 2];
            }



            // For each <input> tag in the triangle
            offset = 0;
            foreach (Input input in mesh.Triangles.Inputs)
            {
                // Get the <source> tag
                source = mesh.GetSource(input.Source);
                if (source == null)
                {
                    offset += 3;
                    continue;
                }


                // For each index in the <p> tag
                for (int i = 0; i < indexCount; i++)
                {
                    // Position in the <p> tag
                    int pos = i * mesh.Triangles.Inputs.Count + input.Offset;


                    // For each param in the source
                    for (int sub = 0; sub < source.Technique.Accessor.Stride; sub++)
                    {
                        int index = mesh.Triangles.Data[pos];

                        float value = source.Array.Data[(index * source.Technique.Accessor.Stride) + sub];

                        try
                        {
                            //buffer[mesh.Triangles.Data[pos] * stridesum + offset + sub] = value;
                            buffer[index * stridesum + offset + sub] = value;
                        }
                        catch
                        {
                        }
                    }
                }

                //
                offset += source.Technique.Accessor.Stride;
            }


            shape.SetIndices(indexbuffer);
            shape.SetVertices(buffer);
            return(shape);
        }