Пример #1
0
        protected unsafe JobHandle?GetTangentsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            Vector4 *output,
            int outputByteStride,
            bool normalized = false
            )
        {
            Profiler.BeginSample("GetTangentsJob");
            JobHandle?jobHandle;

            switch (inputType)
            {
            case GLTFComponentType.Float:
                var jobTangentI = new Jobs.GetTangentsInterleavedJob();
                jobTangentI.inputByteStride  = inputByteStride > 0 ? inputByteStride : 16;
                jobTangentI.input            = (byte *)input;
                jobTangentI.outputByteStride = outputByteStride;
                jobTangentI.result           = output;
                jobHandle = jobTangentI.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            case GLTFComponentType.Short:
                var jobTangent = new Jobs.GetTangentsInt16NormalizedInterleavedJob();
                jobTangent.inputByteStride = inputByteStride > 0 ? inputByteStride : 8;;
                Assert.IsTrue(normalized);
                jobTangent.input            = (System.Int16 *)input;
                jobTangent.outputByteStride = outputByteStride;
                jobTangent.result           = output;
                jobHandle = jobTangent.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            case GLTFComponentType.Byte:
                var jobTangentByte = new Jobs.GetVector4sInt8NormalizedInterleavedJob();
                jobTangentByte.inputByteStride = inputByteStride > 0 ? inputByteStride : 4;
                Assert.IsTrue(normalized);
                jobTangentByte.input            = (sbyte *)input;
                jobTangentByte.outputByteStride = outputByteStride;
                jobTangentByte.result           = output;
                jobHandle = jobTangentByte.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            default:
                logger?.Error(LogCode.TypeUnsupported, "Tangent", inputType.ToString());
                jobHandle = null;
                break;
            }

            Profiler.EndSample();
            return(jobHandle);
        }
Пример #2
0
        static unsafe JobHandle?GetJointsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            uint4 *output,
            int outputByteStride,
            ICodeLogger logger
            )
        {
            Profiler.BeginSample("GetJointsJob");
            JobHandle?jobHandle;

            switch (inputType)
            {
            case GLTFComponentType.UnsignedByte:
                var jointsUInt8Job = new Jobs.ConvertBoneJointsUInt8ToUInt32Job();
                jointsUInt8Job.inputByteStride  = inputByteStride > 0 ? inputByteStride : 4;
                jointsUInt8Job.input            = (byte *)input;
                jointsUInt8Job.outputByteStride = outputByteStride;
                jointsUInt8Job.result           = output;
                jobHandle = jointsUInt8Job.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            case GLTFComponentType.UnsignedShort:
                var jointsUInt16Job = new Jobs.ConvertBoneJointsUInt16ToUInt32Job();
                jointsUInt16Job.inputByteStride  = inputByteStride > 0 ? inputByteStride : 8;
                jointsUInt16Job.input            = (byte *)input;
                jointsUInt16Job.outputByteStride = outputByteStride;
                jointsUInt16Job.result           = output;
                jobHandle = jointsUInt16Job.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            default:
                logger?.Error(LogCode.TypeUnsupported, "Joints", inputType.ToString());
                jobHandle = null;
                break;
            }

            Profiler.EndSample();
            return(jobHandle);
        }
Пример #3
0
        protected unsafe JobHandle?GetWeightsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            Vector4 *output,
            int outputByteStride,
            bool normalized = false
            )
        {
            Profiler.BeginSample("GetWeightsJob");
            JobHandle?jobHandle;

            switch (inputType)
            {
            case GLTFComponentType.Float:
                var jobTangentI = new Jobs.GetVector4sInterleavedJob();
                jobTangentI.inputByteStride  = inputByteStride > 0 ? inputByteStride : 16;
                jobTangentI.input            = (byte *)input;
                jobTangentI.outputByteStride = outputByteStride;
                jobTangentI.result           = output;
                jobHandle = jobTangentI.Schedule(count, GltfImport.DefaultBatchCount);
                break;

            // TODO: Complete those cases
            // case GLTFComponentType.UnsignedShort:
            //     break;
            // case GLTFComponentType.UnsignedByte:
            //     break;
            default:
                logger?.Error(LogCode.TypeUnsupported, "Weights", inputType.ToString());
                jobHandle = null;
                break;
            }

            Profiler.EndSample();
            return(jobHandle);
        }
Пример #4
0
        unsafe JobHandle?GetUvsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            float2 *output,
            int outputByteStride,
            bool normalized = false
            )
        {
            Profiler.BeginSample("PrepareUVs");
            JobHandle?jobHandle = null;

            switch (inputType)
            {
            case GLTFComponentType.Float:
            {
                var jobUv = new Jobs.ConvertUVsFloatToFloatInterleavedJob {
                    inputByteStride  = (inputByteStride > 0) ? inputByteStride : 8,
                    input            = (byte *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = jobUv.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = jobUv.Schedule(count, GltfImport.DefaultBatchCount);
#endif
            }
            break;

            case GLTFComponentType.UnsignedByte:
                if (normalized)
                {
                    var jobUv = new Jobs.ConvertUVsUInt8ToFloatInterleavedNormalizedJob {
                        inputByteStride  = (inputByteStride > 0) ? inputByteStride : 2,
                        input            = (byte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
                    jobHandle = jobUv.Schedule(count, GltfImport.DefaultBatchCount);
                }
                else
                {
                    var jobUv = new Jobs.ConvertUVsUInt8ToFloatInterleavedJob {
                        inputByteStride  = (inputByteStride > 0) ? inputByteStride : 2,
                        input            = (byte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = jobUv.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = jobUv.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                break;

            case GLTFComponentType.UnsignedShort:
                if (normalized)
                {
                    var jobUv = new Jobs.ConvertUVsUInt16ToFloatInterleavedNormalizedJob {
                        inputByteStride  = (inputByteStride > 0) ? inputByteStride : 4,
                        input            = (byte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
                    jobHandle = jobUv.Schedule(count, GltfImport.DefaultBatchCount);
                }
                else
                {
                    var jobUv = new Jobs.ConvertUVsUInt16ToFloatInterleavedJob {
                        inputByteStride  = (inputByteStride > 0) ? inputByteStride : 4,
                        input            = (byte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = jobUv.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = jobUv.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                break;

            case GLTFComponentType.Short:
                if (normalized)
                {
                    var job = new Jobs.ConvertUVsInt16ToFloatInterleavedNormalizedJob {
                        inputByteStride  = inputByteStride > 0 ? inputByteStride : 4,
                        input            = (System.Int16 *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = job.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = job.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                else
                {
                    var job = new Jobs.ConvertUVsInt16ToFloatInterleavedJob {
                        inputByteStride  = inputByteStride > 0 ? inputByteStride : 4,
                        input            = (System.Int16 *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = job.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = job.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                break;

            case GLTFComponentType.Byte:
                var byteStride = inputByteStride > 0 ? inputByteStride : 2;
                if (normalized)
                {
                    var jobInt8 = new Jobs.ConvertUVsInt8ToFloatInterleavedNormalizedJob {
                        inputByteStride  = inputByteStride > 0 ? inputByteStride : 2,
                        input            = (sbyte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = jobInt8.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = jobInt8.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                else
                {
                    var jobInt8 = new Jobs.ConvertUVsInt8ToFloatInterleavedJob {
                        inputByteStride  = inputByteStride > 0 ? inputByteStride : 2,
                        input            = (sbyte *)input,
                        outputByteStride = outputByteStride,
                        result           = output
                    };
#if UNITY_JOBS
                    jobHandle = jobInt8.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                    jobHandle = jobInt8.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                }
                break;

            default:
                logger?.Error(LogCode.TypeUnsupported, "UV", inputType.ToString());
                break;
            }
            Profiler.EndSample();
            return(jobHandle);
        }
Пример #5
0
        protected unsafe JobHandle?GetWeightsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            float4 *output,
            int outputByteStride,
            bool normalized = false
            )
        {
            Profiler.BeginSample("GetWeightsJob");
            JobHandle?jobHandle;

            switch (inputType)
            {
            case GLTFComponentType.Float:
                var jobTangentI = new Jobs.ConvertBoneWeightsFloatToFloatInterleavedJob();
                jobTangentI.inputByteStride  = inputByteStride > 0 ? inputByteStride : 16;
                jobTangentI.input            = (byte *)input;
                jobTangentI.outputByteStride = outputByteStride;
                jobTangentI.result           = output;
#if UNITY_JOBS
                jobHandle = jobTangentI.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = jobTangentI.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;

            case GLTFComponentType.UnsignedShort: {
                var job = new Jobs.ConvertBoneWeightsUInt16ToFloatInterleavedJob {
                    inputByteStride  = inputByteStride > 0 ? inputByteStride : 8,
                    input            = (byte *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = job.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = job.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;
            }

            case GLTFComponentType.UnsignedByte: {
                var job = new Jobs.ConvertBoneWeightsUInt8ToFloatInterleavedJob {
                    inputByteStride  = inputByteStride > 0 ? inputByteStride : 4,
                    input            = (byte *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = job.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = job.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;
            }

            default:
                logger?.Error(LogCode.TypeUnsupported, "Weights", inputType.ToString());
                jobHandle = null;
                break;
            }

            Profiler.EndSample();
            return(jobHandle);
        }
Пример #6
0
        unsafe JobHandle?GetColors32Job(
            void *input,
            GLTFComponentType inputType,
            GLTFAccessorAttributeType attributeType,
            int inputByteStride,
            NativeArray <float4> output
            )
        {
            Profiler.BeginSample("PrepareColors32");
            JobHandle?jobHandle = null;

            if (attributeType == GLTFAccessorAttributeType.VEC3)
            {
                switch (inputType)
                {
                case GLTFComponentType.UnsignedByte:
                {
                    var job = new Jobs.ConvertColorsRGBUInt8ToRGBAFloatJob {
                        input           = (byte *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 3,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.Float:
                {
                    var job = new Jobs.ConvertColorsRGBFloatToRGBAFloatJob {
                        input           = (byte *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 12,
                        result          = (float4 *)output.GetUnsafePtr()
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.UnsignedShort:
                {
                    var job = new Jobs.ConvertColorsRGBUInt16ToRGBAFloatJob {
                        input           = (System.UInt16 *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 6,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                default:
                    logger?.Error(LogCode.ColorFormatUnsupported, attributeType.ToString());
                    break;
                }
            }
            else if (attributeType == GLTFAccessorAttributeType.VEC4)
            {
                switch (inputType)
                {
                case GLTFComponentType.UnsignedByte:
                {
                    var job = new Jobs.ConvertColorsRGBAUInt8ToRGBAFloatJob {
                        input           = (byte *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 4,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.Float:
                {
                    if (inputByteStride == 16 || inputByteStride <= 0)
                    {
                        var job = new Jobs.MemCopyJob {
                            bufferSize = output.Length * 16,
                            input      = input,
                            result     = output.GetUnsafeReadOnlyPtr()
                        };
                        jobHandle = job.Schedule();
                    }
                    else
                    {
                        var job = new Jobs.ConvertColorsRGBAFloatToRGBAFloatJob {
                            input           = (byte *)input,
                            inputByteStride = inputByteStride,
                            result          = (float4 *)output.GetUnsafePtr()
                        };
#if UNITY_JOBS
                        jobHandle = job.ScheduleBatch(output.Length, GltfImport.DefaultBatchCount);
#else
                        jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
#endif
                    }
                }
                break;

                case GLTFComponentType.UnsignedShort:
                {
                    var job = new Jobs.ConvertColorsRGBAUInt16ToRGBAFloatJob {
                        input           = (System.UInt16 *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 8,
                        result          = (float4 *)output.GetUnsafePtr()
                    };
#if UNITY_JOBS
                    jobHandle = job.ScheduleBatch(output.Length, GltfImport.DefaultBatchCount);
#else
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
#endif
                }
                break;

                default:
                    logger?.Error(LogCode.ColorFormatUnsupported, attributeType.ToString());
                    break;
                }
            }
            else
            {
                logger?.Error(LogCode.TypeUnsupported, "color accessor", inputType.ToString());
            }
            Profiler.EndSample();
            return(jobHandle);
        }
Пример #7
0
        protected unsafe JobHandle?GetTangentsJob(
            void *input,
            int count,
            GLTFComponentType inputType,
            int inputByteStride,
            float4 *output,
            int outputByteStride,
            bool normalized = false
            )
        {
            Profiler.BeginSample("GetTangentsJob");
            JobHandle?jobHandle;

            switch (inputType)
            {
            case GLTFComponentType.Float: {
                var jobTangent = new ConvertTangentsFloatToFloatInterleavedJob {
                    inputByteStride  = inputByteStride > 0 ? inputByteStride : 16,
                    input            = (byte *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = jobTangent.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = jobTangent.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;
            }

            case GLTFComponentType.Short: {
                Assert.IsTrue(normalized);
                var jobTangent = new ConvertTangentsInt16ToFloatInterleavedNormalizedJob {
                    inputByteStride  = inputByteStride > 0 ? inputByteStride : 8,
                    input            = (short *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = jobTangent.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = jobTangent.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;
            }

            case GLTFComponentType.Byte: {
                Assert.IsTrue(normalized);
                var jobTangent = new ConvertTangentsInt8ToFloatInterleavedNormalizedJob {
                    inputByteStride  = inputByteStride > 0 ? inputByteStride : 4,
                    input            = (sbyte *)input,
                    outputByteStride = outputByteStride,
                    result           = output
                };
#if UNITY_JOBS
                jobHandle = jobTangent.ScheduleBatch(count, GltfImport.DefaultBatchCount);
#else
                jobHandle = jobTangent.Schedule(count, GltfImport.DefaultBatchCount);
#endif
                break;
            }

            default:
                logger?.Error(LogCode.TypeUnsupported, "Tangent", inputType.ToString());
                jobHandle = null;
                break;
            }

            Profiler.EndSample();
            return(jobHandle);
        }
Пример #8
0
        unsafe JobHandle?GetColors32Job(
            void *input,
            GLTFComponentType inputType,
            GLTFAccessorAttributeType attributeType,
            int inputByteStride,
            NativeArray <Color> output
            )
        {
            Profiler.BeginSample("PrepareColors32");
            JobHandle?jobHandle = null;

            if (attributeType == GLTFAccessorAttributeType.VEC3)
            {
                switch (inputType)
                {
                case GLTFComponentType.UnsignedByte:
                {
                    var job = new Jobs.GetColorsVec3UInt8Job {
                        input           = (byte *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 3,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.Float:
                {
                    var job = new Jobs.GetColorsVec3FloatJob {
                        input           = (float *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 12,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.UnsignedShort:
                {
                    var job = new Jobs.GetColorsVec3UInt16Job {
                        input           = (System.UInt16 *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 6,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                default:
                    logger?.Error(LogCode.ColorFormatUnsupported, attributeType.ToString());
                    break;
                }
            }
            else if (attributeType == GLTFAccessorAttributeType.VEC4)
            {
                switch (inputType)
                {
                case GLTFComponentType.UnsignedByte:
                {
                    var job = new Jobs.GetColorsVec4UInt8Job {
                        input           = (byte *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 4,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                case GLTFComponentType.Float:
                {
                    var job = new Jobs.MemCopyJob();
                    job.bufferSize = output.Length * 16;
                    job.input      = input;
                    job.result     = NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(output);
                    jobHandle      = job.Schedule();
                }
                break;

                case GLTFComponentType.UnsignedShort:
                {
                    var job = new Jobs.GetColorsVec4UInt16Job {
                        input           = (System.UInt16 *)input,
                        inputByteStride = inputByteStride > 0 ? inputByteStride : 8,
                        result          = output
                    };
                    jobHandle = job.Schedule(output.Length, GltfImport.DefaultBatchCount);
                }
                break;

                default:
                    logger?.Error(LogCode.ColorFormatUnsupported, attributeType.ToString());
                    break;
                }
            }
            else
            {
                logger?.Error(LogCode.TypeUnsupported, "color accessor", inputType.ToString());
            }
            Profiler.EndSample();
            return(jobHandle);
        }