Exemplo n.º 1
0
    private VertexUnit[] dVertices; // face

    public VertexPlaneVertical(VertexUnit dVertex1, VertexUnit[] dVertices)
    {
        isFixed = true;

        this.dVertex1 = dVertex1;

        if (dVertices.Length <= 2)
        {
            dVertices = new VertexUnit[3];
        }

        this.dVertices = dVertices;

        RefreshPosition();
    }
Exemplo n.º 2
0
 public void SetUnit(string unit)
 {
     if (string.IsNullOrEmpty(unit))
     {
         return;
     }
     unit = unit.ToLower().FirstCharToUpperCase();
     foreach (VertexUnit unitEnum in System.Enum.GetValues(typeof(VertexUnit)))
     {
         if (unitEnum.ToString() == unit)
         {
             Unit = unitEnum;
             return;
         }
     }
 }
Exemplo n.º 3
0
    public override void InitWithGeometry(Geometry geometry)
    {
        VertexUnit v1 = geometry.VertexUnit(corner.id1);
        VertexUnit v2 = geometry.VertexUnit(corner.id2);
        VertexUnit v3 = geometry.VertexUnit(corner.id3);

        dependencies = new List <VertexUnit>();
        dependencies.Add(v1);
        dependencies.Add(v2);
        dependencies.Add(v3);

        GizmoCorner gizmoCorner = new GizmoCorner(corner);
        GizmoAngle  gizmoAngle  = new GizmoAngle(corner);

        gizmos = new Gizmo[] { gizmoCorner, gizmoAngle };
    }
Exemplo n.º 4
0
    public override void InitWithGeometry(Geometry geometry)
    {
        int count = face.ids.Length;

        VertexUnit[] vertexUnits = new VertexUnit[count];
        for (int i = 0; i < count; i++)
        {
            vertexUnits[i] = geometry.VertexUnit(face.ids[i]);
        }

        dependencies = new List <VertexUnit>(vertexUnits);

        GizmoVolume gizmoVolume = new GizmoVolume(face);

        gizmos = new Gizmo[] { gizmoVolume };
    }
Exemplo n.º 5
0
    private void RemoveObserver(VertexUnit unit, Auxiliary auxiliary)
    {
        List <Auxiliary> observers;

        vertexObservers.TryGetValue(unit, out observers);

        if (observers != null)
        {
            observers.Remove(auxiliary);

            if (observers.Count == 0)
            {
                vertexObservers.Remove(unit);
            }
        }
    }
Exemplo n.º 6
0
    public override void InitWithGeometry(Geometry geometry)
    {
        try {
            VertexUnit unit1 = geometry.VertexUnit(edge.id1);
            VertexUnit unit2 = geometry.VertexUnit(edge.id2);
            units = new VertexUnit[] { };

            GeoEdge geoEdge = new GeoEdge(unit1, unit2);
            elements = new GeoElement[] { geoEdge };

            dependencies.Add(unit1);
            dependencies.Add(unit2);
        } catch (Exception e) {
            Debug.Log(e.Message);
        }
    }
Exemplo n.º 7
0
    public MoveVertexOperation(StateController stateController, GeoCamera geoCamera, Geometry geometry, GeometryBehaviour geometryBehaviour, GeoUI geoUI, VertexUnit vertex, VertexBehaviour vertexBehaviour, bool snap)
    {
        CanRotateCamera = false;
        CanActiveElement = false;

        this.stateController = stateController;

        this.geoCamera = geoCamera;
        this.geometry = geometry;
        this.geometryBehaviour = geometryBehaviour;
        this.inputPanel = geoUI.inputPanel;

        this.vertex = vertex;
        this.vertexBehaviour = vertexBehaviour;

        this.snap = snap;
    }
Exemplo n.º 8
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Initialisation
        //---------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of a particle system.
        /// </summary>
        /// <param name="size">The max number of particles.</param>
        public ParticleSystem2d(int size) : base( )
        {
            textures  = new Textures();
            particles = new Purple.Collections.FixedBag(size);

            // Create a new format
            VertexFormat format = new VertexFormat(
                new Type[] { typeof(PositionStream2), typeof(ColorStream), typeof(TextureStream) });

            // create VertexUnit and IndexStream
            vertexUnit  = new VertexUnit(format, size * 4);
            indexStream = IndexStream.FromQuads(size);

            // load shaders from the resource files
            using (System.IO.Stream fxStream = Purple.IO.ResourceFileSystem.Instance.Open("Purple/Graphics/Particles/Particle2d.fx")) {
                Effect = EffectCompiler.Instance.Compile(fxStream);
            }
        }
Exemplo n.º 9
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Initialisation
        //---------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of a particle system.
        /// </summary>
        /// <param name="size">The max number of particles.</param>
        public LineParticleSystem(int size) : base( )
        {
            textures  = new Textures();
            particles = new FixedRoundBuffer(size);

            // Create a new format
            VertexFormat format = new VertexFormat(
                new Type[] { typeof(PositionStream), typeof(ColorStream), typeof(TextureStream) });

            // create VertexUnit and IndexStream
            vertexUnit  = new VertexUnit(format, 2 + size * 2);
            indexStream = IndexStream.FromChain(size - 1);

            // load shaders from the resource files
            using (System.IO.Stream fxStream = Purple.IO.ResourceFileSystem.Instance.Open("Purple/Graphics/Particles/LineParticle.fx")) {
                Effect = EffectCompiler.Instance.Compile(fxStream);
            }
        }
Exemplo n.º 10
0
 void SoftSkin(Matrix4[] preBound)
 {
     // Apply skinning on all subSets
     for (int iSubSet = 0; iSubSet < data.Length; iSubSet++)
     {
         SubSetData ssData = data[iSubSet];
         if (ssData != null)
         {
             VertexUnit         vu  = mesh.SubSets[iSubSet].VertexUnit;
             PositionStream     ps  = (PositionStream)vu[typeof(PositionStream)];
             IBoneIndicesStream bis = (IBoneIndicesStream)vu[typeof(IBoneIndicesStream)];
             IBoneWeightsStream bws = (IBoneWeightsStream)vu[typeof(IBoneWeightsStream)];
             // currently just the position stream is skinned!
             Skinning.SoftSkin(ps, ssData.Position, bis, bws, preBound, Shadowed);
             ps.Upload();
         }
     }
 }
Exemplo n.º 11
0
    public void GenerateResolvedBody(Geometry geometry)
    {
        SpinAuxiliary auxiliary = new SpinAuxiliary();

        auxiliary.InitWithGeometry(geometry);
        geometryBehaviour = GameObject.Find("/3D/Geometry").GetComponent <GeometryBehaviour>();
        VertexUnit[] vertexUnits = auxiliary.vertices;
        // Cylinder
        if (vertexUnits.Length == 4)
        {
            VertexUnit vertex1 = vertexUnits[0];
            VertexUnit vertex2 = vertexUnits[1];
            VertexUnit vertex3 = vertexUnits[2];
            VertexUnit vertex4 = vertexUnits[3];
            float      radius1 = vertexUnits[3].Position().z;
            float      radius2 = vertexUnits[2].Position().z;

            GeoCircular circular = new GeoCircular(new VertexUnit[] { vertex1, vertex2, vertex3, vertex4 }, radius1, radius2, CircularType.Cylinder);
            geometry.AddGeoCircular(circular);
            VertexSpace circle1 = new VertexSpace(0, vertex4.Position().y, 0);
            VertexSpace circle2 = new VertexSpace(0, vertex3.Position().y, 0);
            geometry.AddGeoCircle(new GeoCircle(circle1, radius1, CircleDirection.Y, false, FaceType.SpreadCylinderCircle));
            geometry.AddGeoCircle(new GeoCircle(circle2, radius2, CircleDirection.Y, false, FaceType.SpreadCylinderCircle));
        }
        // Cone
        else if (vertexUnits.Length == 3)
        {
            VertexUnit vertex1 = vertexUnits[0];
            VertexUnit vertex2 = vertexUnits[1];
            VertexUnit vertex3 = vertexUnits[2];
            float      radius  = vertexUnits[2].Position().z;

            GeoCircular circular = new GeoCircular(new VertexUnit[] { vertex1, vertex2, vertex3 }, radius, radius, CircularType.Cone);
            geometry.AddGeoCircular(circular);
            VertexSpace circle1 = new VertexSpace(0, vertex3.Position().y, 0);
            geometry.AddGeoCircle(new GeoCircle(circle1, radius, CircleDirection.Y, false, FaceType.SpreadConeCircle));
        }
        geometryBehaviour.InitGeometry(geometry);

        StatusButton lockButton = GameObject.Find("LockButton").GetComponent <StatusButton>();

        lockButton.SetStatus(0);
    }
Exemplo n.º 12
0
    public HashSet <VertexUnit> VertexTotalObserveVertices(VertexUnit unit)
    {
        Auxiliary auxiliary = vertexAuxiliaryMap[unit];

        return(AuxiliaryTotalObserveVertices(auxiliary));

        // HashSet<VertexUnit> vertices = new HashSet<VertexUnit>();

        // List<Auxiliary> observers = VertexObservers(unit);

        // foreach (Auxiliary a in observers)
        // {
        //     vertices.UnionWith(a.units);
        //     foreach (VertexUnit item in a.units)
        //         vertices.UnionWith(VertexTotalObserveVertices(item));
        // }

        // return vertices;
    }
Exemplo n.º 13
0
    public void RemoveVertexUnit(int id)
    {
        VertexUnit unit = vertices[id];

        if (unit.isBase)
        {
            return;
        }
        vertices.Remove(id);

        string sign = vertexSignMap[id];

        signVertexMap.Remove(sign);
        vertexSignMap.Remove(id);

        unit.RemoveDependencies();

        // foreach (VertexUnit dependency in unit.dependencies)// TODO
        //     RemoveVertexUnit(dependency.id);
    }
Exemplo n.º 14
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Properties
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Initialisation
        //---------------------------------------------------------------
        /// <summary>
        /// Creates a sky box entity.
        /// </summary>
        /// <param name="size">Size of sky box.</param>
        /// <param name="format"><see cref="VertexFormat"/> to use for skybox.</param>
        public SkyBoxEntity(Vector3 size, VertexFormat format)
        {
            // create streams
            VertexUnit     vertexUnit = new VertexUnit(format, 8);
            PositionStream position   = (PositionStream)vertexUnit[typeof(PositionStream)];
            //TextureStream texture = (TextureStream)vertexUnit[ typeof(TextureStream) ];
            IndexStream index = new IndexStream16(24);

            // fill position data
            position[0] = new Vector3(-size.X, -size.Y, size.Z);
            position[1] = new Vector3(size.X, -size.Y, size.Z);
            position[2] = new Vector3(size.X, -size.Y, -size.Z);
            position[3] = new Vector3(-size.X, -size.Y, -size.Z);
            position[4] = new Vector3(-size.X, size.Y, size.Z);
            position[5] = new Vector3(size.X, size.Y, size.Z);
            position[6] = new Vector3(size.X, size.Y, -size.Z);
            position[7] = new Vector3(-size.X, size.Y, -size.Z);

            subSet = new SubSet(vertexUnit, index);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads the model.
        /// </summary>
        /// <param name="stream">Stream to load model from.</param>
        /// <returns>The loaded model.</returns>
        public Model LoadModel(Stream stream)
        {
            BlendMesh mesh;

            // get header and check if it is ok
            MD2_Header header = (MD2_Header)RawSerializer.Deserialize(stream, typeof(MD2_Header));

            if (header.Ident != 844121161 || header.Version != 8)
            {
                return(null);
            }

            // Load skins
            MD2_Skin[] skinNames = (MD2_Skin[])RawSerializer.DeserializeArray(stream, typeof(MD2_Skin), header.NumSkins);

            // Load texture coordinates
            MD2_TextureCoordinate[] textureCoordinates = (MD2_TextureCoordinate[])RawSerializer.DeserializeArray(stream, typeof(MD2_TextureCoordinate), header.NumTextureCoordinates);

            // Load triangless
            MD2_Triangle[] triangles   = (MD2_Triangle[])RawSerializer.DeserializeArray(stream, typeof(MD2_Triangle), header.NumTris);
            IndexStream    indexStream = new IndexStream16(triangles.Length);

            for (int i = 0; i < triangles.Length; i++)
            {
                // indexStream[i] = triangles[i].VertexIndex[j;
            }

            mesh = new BlendMesh(header.NumFrames);

            // Load frames
            for (int i = 0; i < header.NumFrames; i++)
            {
                MD2_Frame      frame    = (MD2_Frame)RawSerializer.Deserialize(stream, typeof(MD2_Frame));
                MD2_Vertex[]   vertices = (MD2_Vertex[])RawSerializer.DeserializeArray(stream, typeof(MD2_Vertex), header.NumVertices);
                VertexUnit     vu       = new VertexUnit(VertexFormat.Position, vertices.Length);
                PositionStream ps       = (PositionStream)vu[typeof(Purple.Graphics.VertexStreams.PositionStream)];
                mesh.Meshes[i] = new Mesh(new SubSet(vu, indexStream));
            }
            return(new Model(mesh, null));
        }
Exemplo n.º 16
0
    public override void InitWithGeometry(Geometry geometry)
    {
        if (geometry is ResolvedBody)
        {
            resolvedBody = (ResolvedBody)geometry;
        }
        units = new VertexUnit[] { };

        GeoVertex[] geoVertices = geometry.GeoVertices();
        vertices = new VertexUnit[geoVertices.Length];
        int[] ids = new int[geoVertices.Length];
        for (int i = 0; i < geoVertices.Length; i++)
        {
            vertices[i] = geoVertices[i].VertexUnit();
            ids[i]      = vertices[i].id;
        }
        face = new FaceRefer(ids);

        elements = new GeoElement[] { };

        dependencies.AddRange(units);
    }
Exemplo n.º 17
0
    public override void InitWithGeometry(Geometry geometry)
    {
        int count = face.ids.Length;

        VertexUnit[] vertexUnits = new VertexUnit[count];
        for (int i = 0; i < count; i++)
        {
            vertexUnits[i] = geometry.VertexUnit(face.ids[i]);
        }

        VertexPlaneCenter unit = new VertexPlaneCenter(vertexUnits);

        unit.preferredSign = sign;
        geometry.VertexUnitSetId(unit, 0);
        units = new VertexUnit[] { unit };

        GeoVertex geoVertex = new GeoVertex(unit);

        elements = new GeoElement[] { geoVertex };

        dependencies.AddRange(vertexUnits);
    }
Exemplo n.º 18
0
        private SubSetData CreateSubSetData(SubSet subSet)
        {
            VertexUnit vu = subSet.VertexUnit;

            if (!vu.Format.Contains(Semantic.BoneIndices) ||
                !vu.Format.Contains(Semantic.BoneIndices) ||
                !vu.Format.Contains(Semantic.Position))
            {
                return(null);
            }

            SubSetData     ssData    = new SubSetData();
            PositionStream posStream = (PositionStream)vu[typeof(PositionStream)];

            ssData.Position = (Vector3[])posStream.Data.Clone();
            if (vu.Format.Contains(typeof(NormalStream)))
            {
                NormalStream normalStream = (NormalStream)vu[typeof(NormalStream)];
                ssData.Normal = (Vector3[])normalStream.Data.Clone();
            }

            return(ssData);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Prepares a mesh for being used as a shadow Volume.
        /// </summary>
        /// <remarks>In fact the geometry is doubled and an FloatStream is added that contains 1.0f for
        /// vertices that are used for the near cap and 0.0f for the far cap.</remarks>
        /// <param name="mesh">The mesh to prepare.</param>
        public static void PrepareMesh(Mesh mesh)
        {
            SubSets subSets = mesh.SubSets;

            for (int iSubSet = 0; iSubSet < subSets.Count; iSubSet++)
            {
                VertexUnit vu = subSets[iSubSet].VertexUnit;

                IGraphicsStream[] streams = new IGraphicsStream[vu.StreamCount + 1];
                for (int iStream = 0; iStream < vu.StreamCount; iStream++)
                {
                    IGraphicsStream fromStream = vu[iStream];
                    IGraphicsStream toStream   = null;
                    using (Purple.Profiling.Profiler.Instance.Sample("Clone")) {
                        toStream = fromStream.Clone();
                    }
                    using (Purple.Profiling.Profiler.Instance.Sample("Resize")) {
                        toStream.Resize(fromStream.Size * 2);
                    }
                    using (Purple.Profiling.Profiler.Instance.Sample("CopyTo")) {
                        fromStream.Data.CopyTo(toStream.Data, fromStream.Size);
                    }
                    streams[iStream] = toStream;
                }
                using (Purple.Profiling.Profiler.Instance.Sample("FloatStream")) {
                    FloatStream floatStream = new FloatStream(vu.Size * 2);
                    for (int i = 0; i < vu.Size; i++)
                    {
                        floatStream[i]           = 1.0f;
                        floatStream[i + vu.Size] = 0.0f;
                    }
                    streams[vu.StreamCount] = floatStream;
                }
                vu = new VertexUnit(streams);
                subSets[iSubSet].VertexUnit = vu;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Merges two subsets.
        /// </summary>
        /// <param name="subSet">Subset to merge with.</param>
        public void Merge(SubSet subSet)
        {
            if (!CanMerge(subSet))
            {
                throw new GraphicsException("Subsets can't be merged!");
            }

            // Merge vertex unit
            VertexUnit unit = new VertexUnit(VertexUnit.Format, VertexUnit.Size + subSet.VertexUnit.Size);

            VertexUnit.Copy(VertexUnit, 0, unit, 0, VertexUnit.Size);
            VertexUnit.Copy(subSet.VertexUnit, 0, unit, VertexUnit.Size, subSet.VertexUnit.Size);

            VertexUnit.Dispose();
            VertexUnit = unit;

            // Merge index streams
            IndexStream index = IndexStream.Create(IndexStream.Size + subSet.IndexStream.Size, IndexStream.GetType());

            VertexStreams.IndexStream.Copy(IndexStream, 0, index, 0, IndexStream.Size, 0);
            VertexStreams.IndexStream.Copy(subSet.IndexStream, 0, index, IndexStream.Size, subSet.IndexStream.Size, VertexUnit.Size);
            IndexStream.Dispose();
            IndexStream = index;
        }
Exemplo n.º 21
0
 /// <summary>
 /// retrieve n'th PositionStream2 from vertex Unit
 /// </summary>
 /// <param name="unit">vertexUnit to retrieve stream from</param>
 /// <param name="index">number of stream of type(PositionStream2)</param>
 /// <returns>the n'th PositionStream2 of the vertex unit</returns>
 public static PositionStream2 From(VertexUnit unit, int index)
 {
     return((PositionStream2)unit[typeof(PositionStream2), index]);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Changes the format to fit the given semantics.
 /// </summary>
 /// <param name="semantics">Semantics to fit.</param>
 internal void ChangeFormat(Semantic[] semantics)
 {
     VertexUnit.ChangeFormat(semantics);
 }
Exemplo n.º 23
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="vertexUnit"></param>
 public BinormalStream(VertexUnit vertexUnit) : base(vertexUnit)
 {
     Usage = DeclarationUsage.Binormal;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Clones the current <see cref="SubSet"/>, whereby the format of the <see cref="VertexUnit"/>
        /// is changed to the given <see cref="VertexFormat"/>.
        /// </summary>
        /// <remarks>
        /// Uses deep copy (just <see cref="VertexUnit"/> is cloned but not <see cref="IndexStream"/>).
        /// </remarks>
        /// <param name="format"></param>
        /// <returns></returns>
        public SubSet Clone(VertexFormat format)
        {
            SubSet ret = new SubSet(VertexUnit.Clone(format), IndexStream, IndexBufferStart, PrimitiveCount);

            return(ret);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Import a mesh from a stream.
        /// </summary>
        /// <param name="stream">Stream containing mesh data.</param>
        public void Import(Stream stream)
        {
            Profiler.Instance.Begin("Import binary mesh");
            // Header
            BinaryReader reader = new BinaryReader(stream);

            if (ReadString(reader) != "mesh" || ReadString(reader) != "v0.3")
            {
                throw new NotSupportedException("Can't load mesh, file not supported!");
            }

            // Joints
            int jointNum = ReadInt(reader);

            Joint[]   joints     = new Joint[jointNum];
            Matrix4[] jointArray = new Matrix4[jointNum];
            Hashtable jointTable = new Hashtable(joints.Length);

            for (int i = 0; i < joints.Length; i++)
            {
                string name   = ReadString(reader);
                string parent = ReadString(reader);

                reader.Read(matrixBytes, 0, matrixBytes.Length);
                Matrix4 m = Matrix4.From(matrixBytes);

                Joint parentJoint = null;
                if (parent != null && jointTable.Contains(parent))
                {
                    parentJoint = (Joint)jointTable[parent];
                }
                joints[i]        = new Joint(name, i, parentJoint);
                jointArray[i]    = m;
                jointTable[name] = joints[i];
            }
            skeleton = new Skeleton(jointArray, joints);

            // SubSet
            int subSetNum = ReadInt(reader);

            for (int i = 0; i < subSetNum; i++)
            {
                ArrayList streams = new ArrayList(10);
                // Header
                if (ReadString(reader) != "subset")
                {
                    throw new NotSupportedException("Error on loading subSet!");
                }
                string name        = ReadString(reader);
                string parentJoint = ReadString(reader);

                int attributeCount          = ReadInt(reader);
                StringDictionary attributes = new StringDictionary();
                for (int t = 0; t < attributeCount; t++)
                {
                    attributes.Add(ReadString(reader), ReadString(reader));
                }

                // IndexStream
                // Todo Replace ushort.MaxValue with size of vertex unit
                IndexStream indexStream = IndexStream.Create(ReadInt(reader), ushort.MaxValue);
                byte[]      indexBuffer = new byte[indexStream.Size * 4];
                reader.Read(indexBuffer, 0, indexStream.Size * 4);
                for (int t = 0; t < indexStream.Size; t++)
                {
                    indexStream[t] = BitConverter.ToInt32(indexBuffer, t * 4);
                }

                int            vertexSize = ReadInt(reader);
                PositionStream posStream  = new PositionStream(vertexSize);
                streams.Add(posStream);
                byte[] vertexBuffer = new byte[vertexSize * 12];
                reader.Read(vertexBuffer, 0, vertexSize * 12);
                for (int t = 0; t < vertexSize; t++)
                {
                    posStream[t] = Vector3.From(vertexBuffer, 12 * t);
                }

                NormalStream normalStream = new NormalStream(vertexSize);
                streams.Add(normalStream);
                reader.Read(vertexBuffer, 0, vertexSize * 12);
                for (int t = 0; t < vertexSize; t++)
                {
                    normalStream[t] = Vector3.From(vertexBuffer, t * 12);
                }

                ColorStream colorStream = new ColorStream(vertexSize);
                streams.Add(colorStream);
                reader.Read(vertexBuffer, 0, vertexSize * 12);
                for (int t = 0; t < vertexSize; t++)
                {
                    int r = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, t * 12) * 255 + 0.5f), 0, 255);
                    int g = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, 4 + t * 12) * 255 + 0.5f), 0, 255);
                    int b = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, 8 + t * 12) * 255 + 0.5f), 0, 255);
                    colorStream[t] = System.Drawing.Color.FromArgb(r, g, b).ToArgb();
                }

                TextureStream[] textureStreams = new TextureStream[ReadInt(reader)];
                for (int t = 0; t < textureStreams.Length; t++)
                {
                    TextureStream texStream = new TextureStream(vertexSize);
                    streams.Add(texStream);
                    reader.Read(vertexBuffer, 0, vertexSize * 8);
                    for (int j = 0; j < vertexSize; j++)
                    {
                        texStream[j] = Vector2.From(vertexBuffer, j * 8);
                    }
                    textureStreams[t] = texStream;
                }

                IBoneIndicesStream boneStream    = null;
                IBoneWeightsStream weightsStream = null;
                int weightNum = ReadInt(reader);
                if (weightNum != 0)
                {
                    if (HardwareSkinning)
                    {
                        boneStream    = new BoneIndicesStream(vertexSize);
                        weightsStream = new BoneWeightsStream(vertexSize);
                    }
                    else
                    {
                        boneStream    = new SoftwareBoneIndicesStream(vertexSize);
                        weightsStream = new SoftwareBoneWeightsStream(vertexSize);
                    }
                    streams.Add(boneStream);
                    streams.Add(weightsStream);
                    ArrayList[] indicesList = new ArrayList[vertexSize];
                    ArrayList[] weightsList = new ArrayList[vertexSize];
                    for (int t = 0; t < vertexSize; t++)
                    {
                        indicesList[t] = new ArrayList(8);
                        weightsList[t] = new ArrayList(8);
                    }


                    byte[] weightBuffer = new byte[weightNum * 12];
                    reader.Read(weightBuffer, 0, weightNum * 12);
                    for (int t = 0; t < weightNum; t++)
                    {
                        int   vertexIndex = BitConverter.ToInt32(weightBuffer, t * 12);
                        int   jointIndex  = BitConverter.ToInt32(weightBuffer, 4 + t * 12);
                        float weight      = BitConverter.ToSingle(weightBuffer, 8 + t * 12);
                        indicesList[vertexIndex].Add((byte)jointIndex);
                        weightsList[vertexIndex].Add(weight);
                    }

                    for (int t = 0; t < vertexSize; t++)
                    {
                        boneStream.SetIndices(t, (byte[])indicesList[t].ToArray(typeof(byte)));
                        weightsStream.SetWeights(t, (float[])weightsList[t].ToArray(typeof(float)));
                    }
                }

                VertexUnit vertexUnit = new VertexUnit(streams);
                Mesh       mesh       = new Mesh(new SubSet(vertexUnit, indexStream));
                if (model == null)
                {
                    if (skeleton.Joints.Length != 0)
                    {
                        model = new Model(new SkinnedMesh(mesh, skeleton), skeleton);
                    }
                    else
                    {
                        model = new Model(mesh, skeleton);
                    }
                }
                else
                {
                    Joint attachTo = skeleton.RootJoint;
                    if (parentJoint != "")
                    {
                        attachTo = (jointTable[parentJoint] as Joint);
                    }
                    model.AttachModel(new Model(mesh, skeleton), attachTo);
                }
            }
            reader.Close();

            Profiler.Instance.End("Import binary mesh");
        }
Exemplo n.º 26
0
 public void RemoveDependency(VertexUnit vertex)
 {
     dependencies.Remove(vertex);
 }
Exemplo n.º 27
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="vertexUnit"></param>
 public FloatStream(VertexUnit vertexUnit) : base(vertexUnit.Size)
 {
     this.vertexUnit = vertexUnit;
 }
Exemplo n.º 28
0
 /// <summary>
 /// retrieves the first PositionStream2 of a certain vertex unit
 /// </summary>
 /// <param name="unit">vertex unit to retrive stream from</param>
 /// <returns>the first position stream of the vertex unit</returns>
 public static PositionStream2 From(VertexUnit unit)
 {
     return(From(unit, 0));
 }
Exemplo n.º 29
0
        /// <summary>
        /// Clones the current <see cref="SubSet"/>, whereby the format is changed to the fit the semantics given.
        /// </summary>
        /// <remarks>
        /// Uses deep copy (just <see cref="VertexUnit"/> is cloned but not <see cref="IndexStream"/>).
        /// </remarks>
        /// <param name="semantics"></param>
        /// <returns></returns>
        public SubSet Clone(Semantic[] semantics)
        {
            SubSet ret = new SubSet(VertexUnit.Clone(semantics), IndexStream, IndexBufferStart, PrimitiveCount);

            return(ret);
        }
Exemplo n.º 30
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="vertexUnit"></param>
 public PositionStream2(VertexUnit vertexUnit) : base(vertexUnit.Size)
 {
     this.vertexUnit = vertexUnit;
 }