Пример #1
0
 public unsafe Vector Transform(Matrix3x4 *mat)
 {
     return(new Vector()
     {
         X = Dot(mat->_11, mat->_12, mat->_13) + mat->_14,
         Y = Dot(mat->_21, mat->_22, mat->_23) + mat->_24,
         Z = Dot(mat->_31, mat->_32, mat->_33) + mat->_34,
     });
 }
Пример #2
0
    void Awake()
    {
        objBuffer = new ComputeBuffer(characterPoints.Length, sizeof(float));
        Matrix4x4[] bindPosesArray = targetMesh.bindposes;
        bindPoseCount = bindPosesArray.Length;
        bonesBuffer   = new ComputeBuffer(bindPoseCount * characterPoints.Length, sizeof(Matrix3x4));
        bindBuffer    = new ComputeBuffer(bindPoseCount, sizeof(Matrix3x4));
        NativeArray <Matrix3x4> bindNative = new NativeArray <Matrix3x4>(bindPoseCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
        Matrix3x4 *bindPtr = bindNative.Ptr();

        for (int i = 0; i < bindPoseCount; ++i)
        {
            *bindPtr = new Matrix3x4(ref bindPosesArray[i]);
            bindPtr++;
        }
        bindBuffer.SetData(bindNative);
        bindNative.Dispose();
        int[]     triangles = targetMesh.triangles;
        Vector3[] vertices  = targetMesh.vertices;
        //Vector3[] normals = targetMesh.normals;
        //Vector4[] tangents = targetMesh.tangents;
        BoneWeight[] weights = targetMesh.boneWeights;
        Vector2[]    uv      = targetMesh.uv;

        // Debug.LogError("triangles   " + triangles.Length);
        // Debug.LogError("vertices   " + vertices.Length);
        //Debug.LogError("normals   " + normals.Length);
        //Debug.LogError("tangents   " + tangents.Length);
        //  Debug.LogError("weights   " + weights.Length);
        //  Debug.LogError("uv   " + uv.Length);

        NativeArray <SkinPoint> allSkinPoints = new NativeArray <SkinPoint>(vertices.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
        SkinPoint *pointsPtr = allSkinPoints.Ptr();

        for (int i = 0; i < vertices.Length; ++i)
        {
            SkinPoint *currentPtr = pointsPtr + i;
            int        index      = i;
            currentPtr->position = vertices[index];
            Vector3 a = currentPtr->position;
            //currentPtr->tangent = tangents[index];
            //currentPtr->normal = normals[index];
            ref BoneWeight bone = ref weights[index];
            currentPtr->boneWeight = new Vector4(bone.weight0, bone.weight1, bone.weight2, bone.weight3);
            currentPtr->boneIndex  = new Vector4Int(bone.boneIndex0, bone.boneIndex1, bone.boneIndex2, bone.boneIndex3);
            currentPtr->uv         = uv[index];
        }
        protected override void Init(PipelineResources resources)
        {
            block     = new MaterialPropertyBlock();
            objBuffer = new ComputeBuffer(characterPoints.Length, sizeof(AnimState));
            Matrix4x4[] bindPosesArray = targetMesh.bindposes;
            bindPoseCount = bindPosesArray.Length;
            bonesBuffer   = new ComputeBuffer(bindPoseCount * characterPoints.Length, sizeof(Matrix3x4));
            bindBuffer    = new ComputeBuffer(bindPoseCount, sizeof(Matrix3x4));
            NativeArray <Matrix3x4> bindNative = new NativeArray <Matrix3x4>(bindPoseCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            Matrix3x4 *bindPtr = bindNative.Ptr();

            for (int i = 0; i < bindPoseCount; ++i)
            {
                *bindPtr = new Matrix3x4(ref bindPosesArray[i]);
                bindPtr++;
            }
            bindBuffer.SetData(bindNative);
            bindNative.Dispose();
            int[]                   triangles     = targetMesh.triangles;
            Vector3[]               vertices      = targetMesh.vertices;
            Vector3[]               normals       = targetMesh.normals;
            Vector4[]               tangents      = targetMesh.tangents;
            BoneWeight[]            weights       = targetMesh.boneWeights;
            Vector2[]               uv            = targetMesh.uv;
            NativeArray <SkinPoint> allSkinPoints = new NativeArray <SkinPoint>(triangles.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            SkinPoint *             pointsPtr     = allSkinPoints.Ptr();

            for (int i = 0; i < triangles.Length; ++i)
            {
                SkinPoint *currentPtr = pointsPtr + i;
                int        index      = triangles[i];
                currentPtr->position = vertices[index];
                currentPtr->tangent  = tangents[index];
                currentPtr->normal   = normals[index];
                ref BoneWeight bone = ref weights[index];
                currentPtr->boneWeight = new Vector4(bone.weight0, bone.weight1, bone.weight2, bone.weight3);
                currentPtr->boneIndex  = new Vector4Int(bone.boneIndex0, bone.boneIndex1, bone.boneIndex2, bone.boneIndex3);
                currentPtr->uv         = uv[index];
            }