コード例 #1
0
        /////////////////////////////////////////

        //Component_Skeleton.SkinningModeEnum GetSkinningMode( Component_Skeleton skeleton )
        //{
        //	var _override = OverrideSkinningMode.Value;
        //	if( _override != Component_Skeleton.SkinningModeEnum.Auto )
        //		return _override;

        //	var selected = skeleton.SkinningMode.Value;
        //	if( selected != Component_Skeleton.SkinningModeEnum.Auto )
        //		return selected;

        //	if( !hasScale )
        //		return Component_Skeleton.SkinningModeEnum.DualQuaternion;
        //	else
        //		return Component_Skeleton.SkinningModeEnum.Linear;
        //}

        protected virtual void CalculateCPU(Component_Skeleton skeleton, Component_Mesh originalMesh, Component_Mesh modifiableMesh)
        {
            bool dualQuaternion = false;            // GetSkinningMode( skeleton ) == Component_Skeleton.SkinningModeEnum.DualQuaternion;

            for (int nOper = 0; nOper < modifiableMesh.Result.MeshData.RenderOperations.Count; nOper++)
            {
                var sourceOper = originalMesh.Result.MeshData.RenderOperations[nOper];
                var destOper   = modifiableMesh.Result.MeshData.RenderOperations[nOper];

                var position = new ChannelFloat3(sourceOper, destOper, VertexElementSemantic.Position);
                if (position.Exists)
                {
                    var normal  = new ChannelFloat3(sourceOper, destOper, VertexElementSemantic.Normal);
                    var tangent = new ChannelFloat4(sourceOper, destOper, VertexElementSemantic.Tangent);

                    var blendIndices = new SourceChannel <Vector4I>(sourceOper, VertexElementSemantic.BlendIndices, VertexElementType.Integer4);
                    var blendWeights = new SourceChannel <Vector4F>(sourceOper, VertexElementSemantic.BlendWeights, VertexElementType.Float4);

                    if (!blendIndices.Exists || !blendWeights.Exists)
                    {
                        continue;
                    }

                    if (normal.Exists)
                    {
                        if (tangent.Exists)
                        {
                            TransformVertices(
                                dualQuaternion,
                                position.SourceData, normal.SourceData, tangent.SourceData, blendIndices.SourceData, blendWeights.SourceData,
                                position.DestData, normal.DestData, tangent.DestData
                                );
                        }
                        else
                        {
                            TransformVertices(
                                dualQuaternion,
                                position.SourceData, normal.SourceData, blendIndices.SourceData, blendWeights.SourceData,
                                position.DestData, normal.DestData
                                );
                        }
                    }
                    else
                    {
                        TransformVertices(
                            dualQuaternion,
                            position.SourceData, blendIndices.SourceData, blendWeights.SourceData,
                            position.DestData
                            );
                    }

                    position.WriteChannel();
                    normal.WriteChannel();
                    tangent.WriteChannel();
                }
            }
        }
コード例 #2
0
        static void ResetToOriginalMesh(Component_Mesh originalMesh, Component_Mesh modifiableMesh)
        {
            for (int nOper = 0; nOper < modifiableMesh.Result.MeshData.RenderOperations.Count; nOper++)
            {
                var sourceOper = originalMesh.Result.MeshData.RenderOperations[nOper];
                var destOper   = modifiableMesh.Result.MeshData.RenderOperations[nOper];

                var channelsSemantic = new[] { VertexElementSemantic.Position, VertexElementSemantic.Normal, VertexElementSemantic.Tangent, VertexElementSemantic.Bitangent };
                foreach (var semantic in channelsSemantic)
                {
                    var channel = new ChannelFloat3(sourceOper, destOper, semantic);
                    if (channel.Exists)
                    {
                        for (int n = 0; n < channel.DestData.Length; n++)
                        {
                            channel.DestData[n] = channel.SourceData[n];
                        }
                        channel.WriteChannel();
                    }
                }
            }
        }