Exemplo n.º 1
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
        {
            // If we're told we can skip the channel check, then we must be on channel
            Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));

            if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
            {
                base.UpdateResource(channel, skipOnChannelCheck);

                // Read values of properties into local variables
                Point3DCollection  vPositions          = Positions;
                Vector3DCollection vNormals            = Normals;
                PointCollection    vTextureCoordinates = TextureCoordinates;
                Int32Collection    vTriangleIndices    = TriangleIndices;

                // Store the count of this resource's contained collections in local variables.
                int PositionsCount          = (vPositions == null) ? 0 : vPositions.Count;
                int NormalsCount            = (vNormals == null) ? 0 : vNormals.Count;
                int TextureCoordinatesCount = (vTextureCoordinates == null) ? 0 : vTextureCoordinates.Count;
                int TriangleIndicesCount    = (vTriangleIndices == null) ? 0 : vTriangleIndices.Count;

                // Pack & send command packet
                DUCE.MILCMD_MESHGEOMETRY3D data;
                unsafe
                {
                    data.Type                   = MILCMD.MilCmdMeshGeometry3D;
                    data.Handle                 = _duceResource.GetHandle(channel);
                    data.PositionsSize          = (uint)(sizeof(MilPoint3F) * PositionsCount);
                    data.NormalsSize            = (uint)(sizeof(MilPoint3F) * NormalsCount);
                    data.TextureCoordinatesSize = (uint)(sizeof(Point) * TextureCoordinatesCount);
                    data.TriangleIndicesSize    = (uint)(sizeof(Int32) * TriangleIndicesCount);

                    channel.BeginCommand(
                        (byte *)&data,
                        sizeof(DUCE.MILCMD_MESHGEOMETRY3D),
                        (int)(data.PositionsSize +
                              data.NormalsSize +
                              data.TextureCoordinatesSize +
                              data.TriangleIndicesSize)
                        );


                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < PositionsCount; i++)
                    {
                        MilPoint3F resource = CompositionResourceManager.Point3DToMilPoint3F(vPositions.Internal_GetItem(i));
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(MilPoint3F)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < NormalsCount; i++)
                    {
                        MilPoint3F resource = CompositionResourceManager.Vector3DToMilPoint3F(vNormals.Internal_GetItem(i));
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(MilPoint3F)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < TextureCoordinatesCount; i++)
                    {
                        Point resource = vTextureCoordinates.Internal_GetItem(i);
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(Point)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < TriangleIndicesCount; i++)
                    {
                        Int32 resource = vTriangleIndices.Internal_GetItem(i);
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(Int32)
                            );
                    }

                    channel.EndCommand();
                }
            }
        }