protected void TransformAttributes(ref Dictionary <string, AttributeAccessor> attributeAccessors)
 {
     // Flip vectors and triangles to the Unity coordinate system.
     if (attributeAccessors.ContainsKey(SemanticProperties.POSITION))
     {
         AttributeAccessor attributeAccessor = attributeAccessors[SemanticProperties.POSITION];
         SchemaExtensions.ConvertVector3CoordinateSpace(ref attributeAccessor, SchemaExtensions.CoordinateSpaceConversionScale);
     }
     if (attributeAccessors.ContainsKey(SemanticProperties.INDICES))
     {
         AttributeAccessor attributeAccessor = attributeAccessors[SemanticProperties.INDICES];
         SchemaExtensions.FlipFaces(ref attributeAccessor);
     }
     if (attributeAccessors.ContainsKey(SemanticProperties.NORMAL))
     {
         AttributeAccessor attributeAccessor = attributeAccessors[SemanticProperties.NORMAL];
         SchemaExtensions.ConvertVector3CoordinateSpace(ref attributeAccessor, SchemaExtensions.CoordinateSpaceConversionScale);
     }
     // TexCoord goes from 0 to 3 to match GLTFHelpers.BuildMeshAttributes
     for (int i = 0; i < 4; i++)
     {
         if (attributeAccessors.ContainsKey(SemanticProperties.TexCoord(i)))
         {
             AttributeAccessor attributeAccessor = attributeAccessors[SemanticProperties.TexCoord(i)];
             SchemaExtensions.FlipTexCoordArrayV(ref attributeAccessor);
         }
     }
     if (attributeAccessors.ContainsKey(SemanticProperties.TANGENT))
     {
         AttributeAccessor attributeAccessor = attributeAccessors[SemanticProperties.TANGENT];
         SchemaExtensions.ConvertVector4CoordinateSpace(ref attributeAccessor, SchemaExtensions.TangentSpaceConversionScale);
     }
 }
Exemplo n.º 2
0
 public bool Equals(BaseMethodDeclaration compareNode)
 {
     return
         (compareNode != null &&
          Modifiers?.Equals(compareNode.Modifiers) != false &&
          Parameters?.SequenceEqual(compareNode.Parameters) != false &&
          SemanticProperties?.SequenceEqual(compareNode.SemanticProperties) != false &&
          SemanticSignature?.Equals(compareNode.SemanticSignature) != false &&
          base.Equals(compareNode));
 }
Exemplo n.º 3
0
        protected virtual GameObject CreateMeshPrimitive(MeshPrimitive primitive, int meshID, int primitiveIndex)
        {
            var primitiveObj = new GameObject("Primitive");

            var meshFilter = primitiveObj.AddComponent <MeshFilter>();

            if (_assetCache.MeshCache[meshID][primitiveIndex] == null)
            {
                _assetCache.MeshCache[meshID][primitiveIndex] = new MeshCacheData();
            }
            if (_assetCache.MeshCache[meshID][primitiveIndex].LoadedMesh == null)
            {
                if (_assetCache.MeshCache[meshID][primitiveIndex].MeshAttributes.Count == 0)
                {
                    BuildMeshAttributes(primitive, meshID, primitiveIndex);
                }
                var meshAttributes = _assetCache.MeshCache[meshID][primitiveIndex].MeshAttributes;
                var vertexCount    = primitive.Attributes[SemanticProperties.POSITION].Value.Count;

                // todo optimize: There are multiple copies being performed to turn the buffer data into mesh data. Look into reducing them
                UnityEngine.Mesh mesh = new UnityEngine.Mesh
                {
                    vertices = primitive.Attributes.ContainsKey(SemanticProperties.POSITION)
                                                ? meshAttributes[SemanticProperties.POSITION].AccessorContent.AsVertices.ToUnityVector3()
                                                : null,
                    normals = primitive.Attributes.ContainsKey(SemanticProperties.NORMAL)
                                                ? meshAttributes[SemanticProperties.NORMAL].AccessorContent.AsNormals.ToUnityVector3()
                                                : null,

                    uv = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(0))
                                                ? meshAttributes[SemanticProperties.TexCoord(0)].AccessorContent.AsTexcoords.ToUnityVector2()
                                                : null,

                    uv2 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(1))
                                                ? meshAttributes[SemanticProperties.TexCoord(1)].AccessorContent.AsTexcoords.ToUnityVector2()
                                                : null,

                    uv3 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(2))
                                                ? meshAttributes[SemanticProperties.TexCoord(2)].AccessorContent.AsTexcoords.ToUnityVector2()
                                                : null,

                    uv4 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(3))
                                                ? meshAttributes[SemanticProperties.TexCoord(3)].AccessorContent.AsTexcoords.ToUnityVector2()
                                                : null,

                    colors = primitive.Attributes.ContainsKey(SemanticProperties.Color(0))
                                                ? meshAttributes[SemanticProperties.Color(0)].AccessorContent.AsColors.ToUnityColor()
                                                : null,

                    triangles = primitive.Indices != null
                                                ? meshAttributes[SemanticProperties.INDICES].AccessorContent.AsTriangles
                                                : MeshPrimitive.GenerateTriangles(vertexCount),

                    tangents = primitive.Attributes.ContainsKey(SemanticProperties.TANGENT)
                                                ? meshAttributes[SemanticProperties.TANGENT].AccessorContent.AsTangents.ToUnityVector4()
                                                : null
                };

                _assetCache.MeshCache[meshID][primitiveIndex].LoadedMesh = mesh;
            }

            meshFilter.sharedMesh = _assetCache.MeshCache[meshID][primitiveIndex].LoadedMesh;

            var materialWrapper = CreateMaterial(
                primitive.Material != null ? primitive.Material.Value : DefaultMaterial,
                primitive.Material != null ? primitive.Material.Id : -1
                );

            var meshRenderer = primitiveObj.AddComponent <MeshRenderer>();

            meshRenderer.material = materialWrapper.GetContents(primitive.Attributes.ContainsKey(SemanticProperties.Color(0)));

            if (_addColliders)
            {
                var meshCollider = primitiveObj.AddComponent <MeshCollider>();
                meshCollider.sharedMesh = meshFilter.mesh;
            }

            return(primitiveObj);
        }
Exemplo n.º 4
0
        // a mesh *might* decode to multiple prims if there are submeshes
        private MeshPrimitive[] ExportPrimitive(UnityEngine.Mesh meshObj, UnityEngine.Material[] materials, Skin skin = null)
        {
            MyLog.Log("Mesh属性:");
            var skinnedMeshRender = this._target.GetComponent <SkinnedMeshRenderer>();
            var root         = skinnedMeshRender ? this._target.transform : null;
            var materialsObj = new List <UnityEngine.Material>(materials);

            var prims = new MeshPrimitive[meshObj.subMeshCount];

            var byteOffset   = _bufferWriter.BaseStream.Position;
            var bufferViewId = this._root.WriteBufferView(this._bufferId, 0, (int)(_bufferWriter.BaseStream.Position - byteOffset));

            AccessorId aPosition = null, aNormal = null, aTangent = null,
                       aColor0 = null, aTexcoord0 = null, aTexcoord1 = null,
                       aBlendIndex = null, aBlendWeight = null;

            aPosition = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.vertices, SchemaExtensions.CoordinateSpaceConversionScale), bufferViewId, false, null, this._bufferWriter);
            MyLog.Log("-------vertices:" + meshObj.vertices.Length);
            if (meshObj.normals.Length != 0 && (ExportSetting.instance.mesh.normal))
            {
                MyLog.Log("-------normals:" + meshObj.normals.Length);
                aNormal = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.normals, SchemaExtensions.CoordinateSpaceConversionScale), bufferViewId, true, null, this._bufferWriter);
            }

            if (meshObj.tangents.Length != 0 && (ExportSetting.instance.mesh.tangent))
            {
                aTangent = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertVector4CoordinateSpaceAndCopy(meshObj.tangents, SchemaExtensions.TangentSpaceConversionScale), bufferViewId, true, this._bufferWriter);
            }

            if (meshObj.colors.Length != 0 && (ExportSetting.instance.mesh.color))
            {
                MyLog.Log("-------colors:" + meshObj.colors.Length);
                aColor0 = this._root.WriteAccessor(this._bufferId, meshObj.colors, bufferViewId, this._bufferWriter);
            }

            if (meshObj.uv.Length != 0)
            {
                MyLog.Log("-------uv:" + meshObj.uv.Length);
                aTexcoord0 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv), bufferViewId, this._bufferWriter);
            }

            var meshRender = this._target.GetComponent <MeshRenderer>();

            if (meshRender != null && meshRender.lightmapIndex >= 0)
            {
                MyLog.Log("-------uv2:" + meshObj.uv2.Length);
                aTexcoord1 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv2.Length > 0 ? meshObj.uv2 : meshObj.uv), bufferViewId, this._bufferWriter);
                // aTexcoord1 = ExportAccessor(ConvertLightMapUVAndCopy(meshObj.uv2.Length > 0 ? meshObj.uv2 : meshObj.uv, meshRender.lightmapScaleOffset), bufferViewId);
            }
            else
            {
                if (meshObj.uv2.Length != 0 && (ExportSetting.instance.mesh.uv2))
                {
                    MyLog.Log("-------uv2:" + meshObj.uv2.Length);
                    aTexcoord1 = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv2), bufferViewId, this._bufferWriter);
                }
            }

            if (meshObj.boneWeights.Length != 0 && (ExportSetting.instance.mesh.bone))
            {
                MyLog.Log("-------bones:" + meshObj.boneWeights.Length);
                aBlendIndex  = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertBlendIndexAndCopy(meshObj.boneWeights), null, false, this._bufferWriter);
                aBlendWeight = this._root.WriteAccessor(this._bufferId, SchemaExtensions.ConvertBlendWeightAndCopy(meshObj.boneWeights), null, false, this._bufferWriter);
                if (skin != null)
                {
                    /*var index = 0;
                     * var renderer = _target.GetComponent<SkinnedMeshRenderer>();
                     * var bindposes = new Matrix4x4[renderer.bones.Length];
                     *
                     * foreach (var bone in renderer.bones)
                     * {
                     *  for (var i = 0; i < 16; ++i)
                     *  {
                     *      bindposes[index][i] = bone.worldToLocalMatrix[i];
                     *  }
                     *  index++;
                     * }
                     * skin.InverseBindMatrices = ExportAccessor(bindposes);*/
                    skin.InverseBindMatrices = this._root.WriteAccessor(this._bufferId, meshObj.bindposes, null, this._bufferWriter);
                }
            }

            this._root.BufferViews[bufferViewId.Id].ByteLength = (int)(this._bufferWriter.BaseStream.Position - byteOffset);


            MaterialId lastMaterialId = null;

            for (var submesh = 0; submesh < meshObj.subMeshCount; submesh++)
            {
                var primitive = new MeshPrimitive();

                var triangles = meshObj.GetTriangles(submesh);
                primitive.Indices = this._root.WriteAccessor(this._bufferId, SchemaExtensions.FlipFacesAndCopy(triangles), true, this._bufferWriter);

                primitive.Attributes = new Dictionary <string, AccessorId>();
                primitive.Attributes.Add(SemanticProperties.POSITION, aPosition);
                MyLog.Log("-------triangles:" + triangles.Length + "  submesh:" + submesh);
                if (aNormal != null)
                {
                    primitive.Attributes.Add(SemanticProperties.NORMAL, aNormal);
                }

                if (aTangent != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TANGENT, aTangent);
                }

                if (aColor0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.Color(0), aColor0);
                }

                if (aTexcoord0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(0), aTexcoord0);
                }

                if (aTexcoord1 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(1), aTexcoord1);
                }

                if (aBlendIndex != null && aBlendWeight != null)
                {
                    primitive.Attributes.Add(SemanticProperties.Joint(0), aBlendIndex);
                    primitive.Attributes.Add(SemanticProperties.Weight(0), aBlendWeight);
                }

                if (submesh < materialsObj.Count)
                {
                    primitive.Material = new MaterialId
                    {
                        Id   = materialsObj.IndexOf(materialsObj[submesh]),
                        Root = _root
                    };
                    lastMaterialId = primitive.Material;
                }
                else
                {
                    primitive.Material = lastMaterialId;
                }

                prims[submesh] = primitive;
            }

            return(prims);
        }
        // a mesh *might* decode to multiple prims if there are submeshes
        private MeshPrimitive[] ExportPrimitive(GameObject gameObject)
        {
            var filter  = gameObject.GetComponent <MeshFilter>();
            var meshObj = filter.sharedMesh;

            var renderer     = gameObject.GetComponent <MeshRenderer>();
            var materialsObj = renderer.sharedMaterials;

            var prims = new MeshPrimitive[meshObj.subMeshCount];

            // don't export any more accessors if this mesh is already exported
            MeshPrimitive[] primVariations;
            if (_meshToPrims.TryGetValue(meshObj, out primVariations) &&
                meshObj.subMeshCount == primVariations.Length)
            {
                for (var i = 0; i < primVariations.Length; i++)
                {
                    prims[i] = new MeshPrimitive(primVariations[i], _root)
                    {
                        Material = ExportMaterial(materialsObj[i])
                    };
                }

                return(prims);
            }

            AccessorId aPosition = null, aNormal = null, aTangent = null,
                       aTexcoord0 = null, aTexcoord1 = null, aColor0 = null;

            aPosition = ExportAccessor(SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.vertices, SchemaExtensions.CoordinateSpaceConversionScale));

            if (meshObj.normals.Length != 0)
            {
                aNormal = ExportAccessor(SchemaExtensions.ConvertVector3CoordinateSpaceAndCopy(meshObj.normals, SchemaExtensions.CoordinateSpaceConversionScale));
            }

            if (meshObj.tangents.Length != 0)
            {
                aTangent = ExportAccessor(SchemaExtensions.ConvertVector4CoordinateSpaceAndCopy(meshObj.tangents, SchemaExtensions.TangentSpaceConversionScale));
            }

            if (meshObj.uv.Length != 0)
            {
                aTexcoord0 = ExportAccessor(SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv));
            }

            if (meshObj.uv2.Length != 0)
            {
                aTexcoord1 = ExportAccessor(SchemaExtensions.FlipTexCoordArrayVAndCopy(meshObj.uv2));
            }

            if (meshObj.colors.Length != 0)
            {
                aColor0 = ExportAccessor(meshObj.colors);
            }

            MaterialId lastMaterialId = null;

            for (var submesh = 0; submesh < meshObj.subMeshCount; submesh++)
            {
                var primitive = new MeshPrimitive();

                var triangles = meshObj.GetTriangles(submesh);
                primitive.Indices = ExportAccessor(SchemaExtensions.FlipFacesAndCopy(triangles), true);

                primitive.Attributes = new Dictionary <string, AccessorId>();
                primitive.Attributes.Add(SemanticProperties.POSITION, aPosition);

                if (aNormal != null)
                {
                    primitive.Attributes.Add(SemanticProperties.NORMAL, aNormal);
                }
                if (aTangent != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TANGENT, aTangent);
                }
                if (aTexcoord0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(0), aTexcoord0);
                }
                if (aTexcoord1 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.TexCoord(1), aTexcoord1);
                }
                if (aColor0 != null)
                {
                    primitive.Attributes.Add(SemanticProperties.Color(0), aColor0);
                }

                if (submesh < materialsObj.Length)
                {
                    primitive.Material = ExportMaterial(materialsObj[submesh]);
                    lastMaterialId     = primitive.Material;
                }
                else
                {
                    primitive.Material = lastMaterialId;
                }

                prims[submesh] = primitive;
            }

            _meshToPrims[meshObj] = prims;

            return(prims);
        }
Exemplo n.º 6
0
        protected virtual void BuildMeshAttributes(MeshPrimitive primitive, int meshID, int primitiveIndex)
        {
            if (_assetCache.MeshCache[meshID][primitiveIndex].MeshAttributes.Count == 0)
            {
                Dictionary <string, AttributeAccessor> attributeAccessors = new Dictionary <string, AttributeAccessor>(primitive.Attributes.Count + 1);
                foreach (var attributePair in primitive.Attributes)
                {
                    AttributeAccessor AttributeAccessor = new AttributeAccessor()
                    {
                        AccessorId = attributePair.Value,
                        Buffer     = _assetCache.BufferCache[attributePair.Value.Value.BufferView.Value.Buffer.Id]
                    };

                    attributeAccessors[attributePair.Key] = AttributeAccessor;
                }

                if (primitive.Indices != null)
                {
                    AttributeAccessor indexBuilder = new AttributeAccessor()
                    {
                        AccessorId = primitive.Indices,
                        Buffer     = _assetCache.BufferCache[primitive.Indices.Value.BufferView.Value.Buffer.Id]
                    };

                    attributeAccessors[SemanticProperties.INDICES] = indexBuilder;
                }

                GLTFHelpers.BuildMeshAttributes(ref attributeAccessors);

                // Flip vectors and triangles to the Unity coordinate system.
                if (attributeAccessors.ContainsKey(SemanticProperties.POSITION))
                {
                    NumericArray resultArray = attributeAccessors[SemanticProperties.POSITION].AccessorContent;
                    resultArray.AsVertices = GLTFUnityHelpers.FlipVectorArrayHandedness(resultArray.AsVertices);
                    attributeAccessors[SemanticProperties.POSITION].AccessorContent = resultArray;
                }
                if (attributeAccessors.ContainsKey(SemanticProperties.INDICES))
                {
                    NumericArray resultArray = attributeAccessors[SemanticProperties.INDICES].AccessorContent;
                    resultArray.AsTriangles = GLTFUnityHelpers.FlipFaces(resultArray.AsTriangles);
                    attributeAccessors[SemanticProperties.INDICES].AccessorContent = resultArray;
                }
                if (attributeAccessors.ContainsKey(SemanticProperties.NORMAL))
                {
                    NumericArray resultArray = attributeAccessors[SemanticProperties.NORMAL].AccessorContent;
                    resultArray.AsNormals = GLTFUnityHelpers.FlipVectorArrayHandedness(resultArray.AsNormals);
                    attributeAccessors[SemanticProperties.NORMAL].AccessorContent = resultArray;
                }
                // TexCoord goes from 0 to 3 to match GLTFHelpers.BuildMeshAttributes
                for (int i = 0; i < 4; i++)
                {
                    if (attributeAccessors.ContainsKey(SemanticProperties.TexCoord(i)))
                    {
                        NumericArray resultArray = attributeAccessors[SemanticProperties.TexCoord(i)].AccessorContent;
                        resultArray.AsTexcoords = GLTFUnityHelpers.FlipTexCoordArrayV(resultArray.AsTexcoords);
                        attributeAccessors[SemanticProperties.TexCoord(i)].AccessorContent = resultArray;
                    }
                }
                if (attributeAccessors.ContainsKey(SemanticProperties.TANGENT))
                {
                    NumericArray resultArray = attributeAccessors[SemanticProperties.TANGENT].AccessorContent;
                    resultArray.AsTangents = GLTFUnityHelpers.FlipVectorArrayHandedness(resultArray.AsTangents);
                    attributeAccessors[SemanticProperties.TANGENT].AccessorContent = resultArray;
                }

                _assetCache.MeshCache[meshID][primitiveIndex].MeshAttributes = attributeAccessors;
            }
        }
        protected virtual void CreateMeshPrimitive(MeshPrimitive primitive, string meshName, int meshID, int primitiveIndex)
        {
            var meshAttributes = BuildMeshAttributes(primitive, meshID, primitiveIndex);
            var vertexCount    = primitive.Attributes[SemanticProperties.POSITION].Value.Count;

            UnityEngine.Mesh mesh = new UnityEngine.Mesh
            {
                vertices = primitive.Attributes.ContainsKey(SemanticProperties.POSITION)
                                        ? meshAttributes[SemanticProperties.POSITION].AccessorContent.AsVertices.ToUnityVector3()
                                        : null,
                normals = primitive.Attributes.ContainsKey(SemanticProperties.NORMAL)
                                        ? meshAttributes[SemanticProperties.NORMAL].AccessorContent.AsNormals.ToUnityVector3()
                                        : null,

                uv = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(0))
                                        ? meshAttributes[SemanticProperties.TexCoord(0)].AccessorContent.AsTexcoords.ToUnityVector2()
                                        : null,

                uv2 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(1))
                                        ? meshAttributes[SemanticProperties.TexCoord(1)].AccessorContent.AsTexcoords.ToUnityVector2()
                                        : null,

                uv3 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(2))
                                        ? meshAttributes[SemanticProperties.TexCoord(2)].AccessorContent.AsTexcoords.ToUnityVector2()
                                        : null,

                uv4 = primitive.Attributes.ContainsKey(SemanticProperties.TexCoord(3))
                                        ? meshAttributes[SemanticProperties.TexCoord(3)].AccessorContent.AsTexcoords.ToUnityVector2()
                                        : null,

                colors = primitive.Attributes.ContainsKey(SemanticProperties.Color(0))
                                        ? meshAttributes[SemanticProperties.Color(0)].AccessorContent.AsColors.ToUnityColor()
                                        : null,

                triangles = primitive.Indices != null
                                        ? meshAttributes[SemanticProperties.INDICES].AccessorContent.AsTriangles
                                        : MeshPrimitive.GenerateTriangles(vertexCount),

                tangents = primitive.Attributes.ContainsKey(SemanticProperties.TANGENT)
                                        ? meshAttributes[SemanticProperties.TANGENT].AccessorContent.AsTangents.ToUnityVector4(true)
                                        : null
            };

            if (primitive.Attributes.ContainsKey(SemanticProperties.JOINT) && primitive.Attributes.ContainsKey(SemanticProperties.WEIGHT))
            {
                Vector4[] bones   = new Vector4[1];
                Vector4[] weights = new Vector4[1];

                LoadSkinnedMeshAttributes(meshID, primitiveIndex, ref bones, ref weights);
                if (bones.Length != mesh.vertices.Length || weights.Length != mesh.vertices.Length)
                {
                    Debug.LogError("Not enough skinning data (bones:" + bones.Length + " weights:" + weights.Length + "  verts:" + mesh.vertices.Length + ")");
                    return;
                }

                BoneWeight[] bws           = new BoneWeight[mesh.vertices.Length];
                int          maxBonesIndex = 0;
                for (int i = 0; i < bws.Length; ++i)
                {
                    // Unity seems expects the the sum of weights to be 1.
                    float[] normalizedWeights = GLTFUtils.normalizeBoneWeights(weights[i]);

                    bws[i].boneIndex0 = (int)bones[i].x;
                    bws[i].weight0    = normalizedWeights[0];

                    bws[i].boneIndex1 = (int)bones[i].y;
                    bws[i].weight1    = normalizedWeights[1];

                    bws[i].boneIndex2 = (int)bones[i].z;
                    bws[i].weight2    = normalizedWeights[2];

                    bws[i].boneIndex3 = (int)bones[i].w;
                    bws[i].weight3    = normalizedWeights[3];

                    maxBonesIndex = (int)Mathf.Max(maxBonesIndex, bones[i].x, bones[i].y, bones[i].z, bones[i].w);
                }

                mesh.boneWeights = bws;

                // initialize inverseBindMatrix array with identity matrix in order to output a valid mesh object
                Matrix4x4[] bindposes = new Matrix4x4[maxBonesIndex + 1];
                for (int j = 0; j <= maxBonesIndex; ++j)
                {
                    bindposes[j] = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
                }
                mesh.bindposes = bindposes;
            }

            if (primitive.Targets != null && primitive.Targets.Count > 0)
            {
                for (int b = 0; b < primitive.Targets.Count; ++b)
                {
                    Vector3[] deltaVertices = new Vector3[primitive.Targets[b]["POSITION"].Value.Count];
                    Vector3[] deltaNormals  = new Vector3[primitive.Targets[b]["POSITION"].Value.Count];
                    Vector3[] deltaTangents = new Vector3[primitive.Targets[b]["POSITION"].Value.Count];

                    if (primitive.Targets[b].ContainsKey("POSITION"))
                    {
                        NumericArray num = new NumericArray();
                        deltaVertices = primitive.Targets[b]["POSITION"].Value.AsVector3Array(ref num, _assetCache.BufferCache[0], false).ToUnityVector3(true);
                    }
                    if (primitive.Targets[b].ContainsKey("NORMAL"))
                    {
                        NumericArray num = new NumericArray();
                        deltaNormals = primitive.Targets[b]["NORMAL"].Value.AsVector3Array(ref num, _assetCache.BufferCache[0], true).ToUnityVector3(true);
                    }
                    //if (primitive.Targets[b].ContainsKey("TANGENT"))
                    //{
                    //	deltaTangents = primitive.Targets[b]["TANGENT"].Value.AsVector3Array(ref num, _assetCache.BufferCache[0], true).ToUnityVector3(true);
                    //}

                    mesh.AddBlendShapeFrame(GLTFUtils.buildBlendShapeName(meshID, b), 1.0f, deltaVertices, deltaNormals, deltaTangents);
                }
            }

            mesh.RecalculateBounds();
            mesh.RecalculateTangents();
            mesh = _assetManager.saveMesh(mesh, meshName + "_" + meshID + "_" + primitiveIndex);
            UnityEngine.Material material = primitive.Material != null && primitive.Material.Id >= 0 ? getMaterial(primitive.Material.Id) : defaultMaterial;

            _assetManager.addPrimitiveMeshData(meshID, primitiveIndex, mesh, material);
        }
Exemplo n.º 8
0
        void SetupMauiLayout()
        {
            const string loremIpsum =
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
                "Quisque ut dolor metus. Duis vel iaculis mauris, sit amet finibus mi. " +
                "Etiam congue ornare risus, in facilisis libero tempor eget. " +
                "Phasellus mattis mollis libero ut semper. In sit amet sapien odio. " +
                "Sed interdum ullamcorper dui eu rutrum. Vestibulum non sagittis justo. " +
                "Cras rutrum scelerisque elit, et porta est lobortis ac. " +
                "Pellentesque eu ornare tortor. Sed bibendum a nisl at laoreet.";

            var verticalStack = new VerticalStackLayout()
            {
                Spacing = 5, BackgroundColor = Color.AntiqueWhite
            };
            var horizontalStack = new HorizontalStackLayout()
            {
                Spacing = 2, BackgroundColor = Color.CornflowerBlue
            };

            verticalStack.Add(CreateSampleGrid());

            verticalStack.Add(new Label {
                Text = " ", Padding = new Thickness(10)
            });
            var label = new Label {
                Text = "End-aligned text", BackgroundColor = Color.Fuchsia, HorizontalTextAlignment = TextAlignment.End
            };

            label.Margin = new Thickness(15, 10, 20, 15);

            SemanticProperties.SetHint(label, "Hint Text");
            SemanticProperties.SetDescription(label, "Description Text");

            verticalStack.Add(label);
            verticalStack.Add(new Label {
                Text = "This should be BIG text!", FontSize = 24, HorizontalOptions = LayoutOptions.End
            });

            SemanticProperties.SetHeadingLevel((BindableObject)verticalStack.Children.Last(), SemanticHeadingLevel.Level1);
            verticalStack.Add(new Label {
                Text = "This should be BOLD text!", FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.Center
            });
            verticalStack.Add(new Label {
                Text = "This should be a CUSTOM font!", FontFamily = "Dokdo"
            });
            verticalStack.Add(new Label {
                Text = "This should have padding", Padding = new Thickness(40), BackgroundColor = Color.LightBlue
            });
            verticalStack.Add(new Label {
                Text = loremIpsum
            });
            verticalStack.Add(new Label {
                Text = loremIpsum, MaxLines = 2
            });
            verticalStack.Add(new Label {
                Text = loremIpsum, LineBreakMode = LineBreakMode.TailTruncation
            });
            verticalStack.Add(new Label {
                Text = loremIpsum, MaxLines = 2, LineBreakMode = LineBreakMode.TailTruncation
            });
            verticalStack.Add(new Label {
                Text = "This should have five times the line height! " + loremIpsum, LineHeight = 5, MaxLines = 2
            });

            SemanticProperties.SetHeadingLevel((BindableObject)verticalStack.Children.Last(), SemanticHeadingLevel.Level2);

            var visibleClearButtonEntry = new Entry()
            {
                ClearButtonVisibility = ClearButtonVisibility.WhileEditing, Placeholder = "This Entry will show clear button if has input."
            };
            var hiddenClearButtonEntry = new Entry()
            {
                ClearButtonVisibility = ClearButtonVisibility.Never, Placeholder = "This Entry will not..."
            };

            verticalStack.Add(visibleClearButtonEntry);
            verticalStack.Add(hiddenClearButtonEntry);

            verticalStack.Add(new Editor {
                Placeholder = "This is an editor placeholder."
            });

            var underlineLabel = new Label {
                Text = "underline", TextDecorations = TextDecorations.Underline
            };

            verticalStack.Add(underlineLabel);

            verticalStack.Add(new ActivityIndicator());
            verticalStack.Add(new ActivityIndicator {
                Color = Color.Red, IsRunning = true
            });

            var button = new Button()
            {
                Text = _viewModel.Text, WidthRequest = 200
            };

            button.Clicked += async(sender, e) =>
            {
                var events = _services.GetRequiredService <ILifecycleEventService>();
                events.InvokeEvents <Action <string> >("CustomEventName", action => action("VALUE"));

                var location = await Geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Lowest));

                Debug.WriteLine($"I tracked you down to {location.Latitude}, {location.Longitude}! You can't hide!");
            };

            var button2 = new Button()
            {
                TextColor       = Color.Green,
                Text            = "Hello I'm a button",
                BackgroundColor = Color.Purple,
                Margin          = new Thickness(12)
            };

            horizontalStack.Add(button);
            horizontalStack.Add(button2);

            horizontalStack.Add(new Label {
                Text = "And these buttons are in a HorizontalStackLayout", VerticalOptions = LayoutOptions.Center
            });

            verticalStack.Add(horizontalStack);

            var paddingButton = new Button
            {
                Padding         = new Thickness(40),
                Text            = "This button has a padding!!",
                BackgroundColor = Color.Purple,
            };

            verticalStack.Add(paddingButton);
            verticalStack.Add(new Button {
                Text = "CharacterSpacing"
            });
            verticalStack.Add(new Button {
                CharacterSpacing = 8, Text = "CharacterSpacing"
            });

            var checkbox = new CheckBox();

            checkbox.CheckedChanged += (sender, e) =>
            {
                Debug.WriteLine($"Checked Changed to '{e.Value}'");
            };
            verticalStack.Add(checkbox);
            verticalStack.Add(new CheckBox {
                BackgroundColor = Color.LightPink
            });
            verticalStack.Add(new CheckBox {
                IsChecked = true, Color = Color.Aquamarine
            });

            verticalStack.Add(new Editor());
            verticalStack.Add(new Editor {
                Text = "Editor"
            });
            verticalStack.Add(new Editor {
                Text = "Lorem ipsum dolor sit amet", MaxLength = 10
            });
            verticalStack.Add(new Editor {
                Text = "Predictive Text Off", IsTextPredictionEnabled = false
            });
            verticalStack.Add(new Editor {
                Text = "Lorem ipsum dolor sit amet", FontSize = 10, FontFamily = "dokdo_regular"
            });
            verticalStack.Add(new Editor {
                Text = "ReadOnly Editor", IsReadOnly = true
            });


            var entry = new Entry();

            entry.TextChanged += (sender, e) =>
            {
                Debug.WriteLine($"Text Changed from '{e.OldTextValue}' to '{e.NewTextValue}'");
            };

            verticalStack.Add(entry);
            verticalStack.Add(new Entry {
                Text = "Entry", TextColor = Color.DarkRed, FontFamily = "Dokdo", MaxLength = -1
            });
            verticalStack.Add(new Entry {
                IsPassword = true, TextColor = Color.Black, Placeholder = "Pasword Entry"
            });
            verticalStack.Add(new Entry {
                IsTextPredictionEnabled = false
            });
            verticalStack.Add(new Entry {
                Placeholder = "This should be placeholder text"
            });
            verticalStack.Add(new Entry {
                Text = "This should be read only property", IsReadOnly = true
            });
            verticalStack.Add(new Entry {
                MaxLength = 5, Placeholder = "MaxLength text"
            });
            verticalStack.Add(new Entry {
                Text = "This should be text with character spacing", CharacterSpacing = 10
            });
            verticalStack.Add(new Entry {
                Keyboard = Keyboard.Numeric, Placeholder = "Numeric Entry"
            });
            verticalStack.Add(new Entry {
                Keyboard = Keyboard.Email, Placeholder = "Email Entry"
            });

            verticalStack.Add(new ProgressBar {
                Progress = 0.5
            });
            verticalStack.Add(new ProgressBar {
                Progress = 0.5, BackgroundColor = Color.LightCoral
            });
            verticalStack.Add(new ProgressBar {
                Progress = 0.5, ProgressColor = Color.Purple
            });

            var searchBar = new SearchBar();

            searchBar.CharacterSpacing = 4;
            searchBar.Text             = "A search query";
            verticalStack.Add(searchBar);

            var placeholderSearchBar = new SearchBar();

            placeholderSearchBar.Placeholder = "Placeholder";
            verticalStack.Add(placeholderSearchBar);


            var monkeyList = new List <string>
            {
                "Baboon",
                "Capuchin Monkey",
                "Blue Monkey",
                "Squirrel Monkey",
                "Golden Lion Tamarin",
                "Howler Monkey",
                "Japanese Macaque"
            };

            var picker = new Picker {
                Title = "Select a monkey", FontFamily = "Dokdo"
            };

            picker.ItemsSource = monkeyList;
            verticalStack.Add(picker);

            verticalStack.Add(new Slider());

            verticalStack.Add(new Stepper());
            verticalStack.Add(new Stepper {
                BackgroundColor = Color.IndianRed
            });
            verticalStack.Add(new Stepper {
                Minimum = 0, Maximum = 10, Value = 5
            });

            verticalStack.Add(new Switch());
            verticalStack.Add(new Switch()
            {
                OnColor = Color.Green
            });
            verticalStack.Add(new Switch()
            {
                ThumbColor = Color.Yellow
            });
            verticalStack.Add(new Switch()
            {
                OnColor = Color.Green, ThumbColor = Color.Yellow
            });

            verticalStack.Add(new DatePicker());
            verticalStack.Add(new DatePicker {
                CharacterSpacing = 6
            });
            verticalStack.Add(new DatePicker {
                FontSize = 24
            });

            verticalStack.Add(new TimePicker());
            verticalStack.Add(new TimePicker {
                Time = TimeSpan.FromHours(8), CharacterSpacing = 6
            });

            verticalStack.Add(new Image()
            {
                Source = "dotnet_bot.png"
            });

            Content = new ScrollView
            {
                Content = verticalStack
            };
        }
Exemplo n.º 9
0
        void SetupMauiLayout()
        {
            var verticalStack = new VerticalStackLayout()
            {
                Spacing = 5, BackgroundColor = Colors.AntiqueWhite
            };
            var horizontalStack = new HorizontalStackLayout()
            {
                Spacing = 2, BackgroundColor = Colors.CornflowerBlue
            };

            //verticalStack.Add(CreateSampleGrid());
            verticalStack.Add(CreateResizingButton());

            AddTextResizeDemo(verticalStack);
            verticalStack.Add(CreateTransformations());
            verticalStack.Add(CreateAnimations());
            verticalStack.Add(CreateShapes());

            verticalStack.Add(new Label {
                Text = " ", Padding = new Thickness(10)
            });
            var label = new Label {
                Text = "End-aligned text", BackgroundColor = Colors.Fuchsia, HorizontalTextAlignment = TextAlignment.End
            };

            label.Margin = new Thickness(15, 10, 20, 15);

            SemanticProperties.SetHint(label, "Hint Text");
            SemanticProperties.SetDescription(label, "Description Text");

            verticalStack.Add(label);
            verticalStack.Add(new Label {
                Text = "This should be BIG text!", FontSize = 24, HorizontalOptions = LayoutOptions.End
            });

            SemanticProperties.SetHeadingLevel((BindableObject)verticalStack.Children.Last(), SemanticHeadingLevel.Level1);
            verticalStack.Add(new Label {
                Text = "This should be BOLD text!", FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.Center
            });
            verticalStack.Add(new Label {
                Text = "This should have character spacing!", CharacterSpacing = 3
            });
            verticalStack.Add(new Label {
                Text = "This should be a CUSTOM font!", FontFamily = "Dokdo"
            });
            verticalStack.Add(
                new Button
            {
                Text     = "Push a Page",
                Rotation = 15,
                Scale    = 1.5,
                Command  = new Command(async() =>
                {
                    await Navigation.PushAsync(new SemanticsPage());
                })
            }
                );

            verticalStack.Add(new Label {
                Text = "This should have padding", Padding = new Thickness(40), BackgroundColor = Colors.LightBlue
            });
            verticalStack.Add(new Label {
                Text = LoremIpsum
            });
            verticalStack.Add(new Label {
                Text = LoremIpsum, MaxLines = 2
            });
            verticalStack.Add(new Label {
                Text = LoremIpsum, LineBreakMode = LineBreakMode.TailTruncation
            });
            verticalStack.Add(new Label {
                Text = LoremIpsum, MaxLines = 2, LineBreakMode = LineBreakMode.TailTruncation
            });
            verticalStack.Add(new Label {
                Text = "This should have five times the line height! " + LoremIpsum, LineHeight = 5, MaxLines = 2
            });
            verticalStack.Add(new Label
            {
                FontSize   = 24,
                Text       = "LinearGradient Text",
                Background = new LinearGradientBrush(
                    new GradientStopCollection
                {
                    new GradientStop(Colors.Green, 0),
                    new GradientStop(Colors.Blue, 1)
                },
                    new Point(0, 0),
                    new Point(1, 0))
            });
            verticalStack.Add(new Label
            {
                Text       = "RadialGradient",
                Padding    = new Thickness(30),
                Background = new RadialGradientBrush(
                    new GradientStopCollection
                {
                    new GradientStop(Colors.DarkBlue, 0),
                    new GradientStop(Colors.Yellow, 0.6f),
                    new GradientStop(Colors.LightPink, 1)
                },
                    new Point(0.5, 0.5),
                    0.3f)
            });

            SemanticProperties.SetHeadingLevel((BindableObject)verticalStack.Children.Last(), SemanticHeadingLevel.Level2);

            var visibleClearButtonEntry = new Entry()
            {
                ClearButtonVisibility = ClearButtonVisibility.WhileEditing, Placeholder = "This Entry will show clear button if has input."
            };
            var hiddenClearButtonEntry = new Entry()
            {
                ClearButtonVisibility = ClearButtonVisibility.Never, Placeholder = "This Entry will not..."
            };

            verticalStack.Add(visibleClearButtonEntry);
            verticalStack.Add(hiddenClearButtonEntry);

            verticalStack.Add(new Editor {
                Text = "Editor TextColor", TextColor = Colors.Olive
            });
            verticalStack.Add(new Editor {
                Text = "Editor using CharacterSpacing", CharacterSpacing = 10
            });
            verticalStack.Add(new Editor {
                Placeholder = "This is an editor placeholder."
            });
            verticalStack.Add(new Editor {
                Placeholder = "Editor PlaceholderColor", PlaceholderColor = Colors.Green
            });

            var paddingButton = new Button
            {
                Padding         = new Thickness(40),
                Text            = "This button has a padding!!",
                BackgroundColor = Colors.Purple,
            };

            verticalStack.Add(paddingButton);

            var underlineLabel = new Label {
                Text = "underline", TextDecorations = TextDecorations.Underline
            };

            verticalStack.Add(underlineLabel);

            verticalStack.Add(new ActivityIndicator());
            verticalStack.Add(new ActivityIndicator {
                Color = Colors.Red, IsRunning = true
            });

            var button = new Button()
            {
                Text = _viewModel.Text, WidthRequest = 200
            };

            button.Clicked += async(sender, e) =>
            {
                var events = _services.GetRequiredService <ILifecycleEventService>();
                events.InvokeEvents <Action <string> >("CustomEventName", action => action("VALUE"));

                var location = await Geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Lowest));

                Debug.WriteLine($"I tracked you down to {location.Latitude}, {location.Longitude}! You can't hide!");
            };

            var button2 = new Button()
            {
                TextColor = Colors.Green,
                Text      = "Hello I'm a button",
                //	BackgroundColor = Color.Purple,
                Margin = new Thickness(12)
            };

            horizontalStack.Add(button);
            horizontalStack.Add(button2);

            horizontalStack.Add(new Label {
                Text = "And these buttons are in a HorizontalStackLayout", VerticalOptions = LayoutOptions.Center
            });

            verticalStack.Add(horizontalStack);

            verticalStack.Add(new Button {
                Text = "CharacterSpacing"
            });
            verticalStack.Add(new Button {
                CharacterSpacing = 8, Text = "CharacterSpacing"
            });

            verticalStack.Add(new RedButton {
                Text = "Dynamically Registered"
            });
            verticalStack.Add(new CustomButton {
                Text = "Button Registered to Compat Renderer"
            });

            var checkbox = new CheckBox();

            checkbox.CheckedChanged += (sender, e) =>
            {
                Debug.WriteLine($"Checked Changed to '{e.Value}'");
            };
            verticalStack.Add(checkbox);
            verticalStack.Add(new CheckBox {
                BackgroundColor = Colors.LightPink
            });
            verticalStack.Add(new CheckBox {
                IsChecked = true, Color = Colors.Aquamarine
            });

            var editor = new Editor();

            editor.Completed += (sender, args) =>
            {
                Debug.WriteLine($"Editor Completed");
            };

            verticalStack.Add(editor);
            verticalStack.Add(new Editor {
                Text = "Editor"
            });
            verticalStack.Add(new Editor {
                Text = "Lorem ipsum dolor sit amet", MaxLength = 10
            });
            verticalStack.Add(new Editor {
                Text = "Predictive Text Off", IsTextPredictionEnabled = false
            });
            verticalStack.Add(new Editor {
                Text = "Lorem ipsum dolor sit amet", FontSize = 10, FontFamily = "Dokdo"
            });
            verticalStack.Add(new Editor {
                Text = "ReadOnly Editor", IsReadOnly = true
            });

            var entry = new Entry();

            entry.TextChanged += (sender, e) =>
            {
                Debug.WriteLine($"Text Changed from '{e.OldTextValue}' to '{e.NewTextValue}'");
            };

            var entryMargin = new Thickness(10, 0);

            verticalStack.Add(entry);
            verticalStack.Add(new Entry {
                Text = "Entry with custom Font", TextColor = Colors.DarkRed, FontFamily = "Dokdo", MaxLength = -1, Margin = entryMargin
            });
            verticalStack.Add(new Entry {
                IsPassword = true, TextColor = Colors.Black, Placeholder = "Pasword Entry", Margin = entryMargin
            });
            verticalStack.Add(new Entry {
                IsTextPredictionEnabled = false
            });
            verticalStack.Add(new Entry {
                Placeholder = "This should be placeholder text", Margin = entryMargin
            });
            verticalStack.Add(new Entry {
                Text = "This should be read only property", IsReadOnly = true, Margin = entryMargin
            });
            verticalStack.Add(new Entry {
                MaxLength = 5, Placeholder = "MaxLength text", Margin = entryMargin
            });
            verticalStack.Add(new Entry {
                Text = "This should be text with character spacing", CharacterSpacing = 10
            });
            verticalStack.Add(new Entry {
                Keyboard = Keyboard.Numeric, Placeholder = "Numeric Entry"
            });
            verticalStack.Add(new Entry {
                Keyboard = Keyboard.Email, Placeholder = "Email Entry"
            });
            verticalStack.Add(new Entry {
                Placeholder = "This is a blue text box", BackgroundColor = Colors.CornflowerBlue
            });

            verticalStack.Add(CreateSampleCursorSelection());

            verticalStack.Add(new GraphicsView {
                Drawable = new TestDrawable(), HeightRequest = 50, WidthRequest = 200
            });

            verticalStack.Add(new ProgressBar {
                Progress = 0.5
            });
            verticalStack.Add(new ProgressBar {
                Progress = 0.5, BackgroundColor = Colors.LightCoral
            });
            verticalStack.Add(new ProgressBar {
                Progress = 0.5, ProgressColor = Colors.Purple
            });

            verticalStack.Add(new SearchBar {
                CharacterSpacing = 4, Text = "A search query", TextColor = Colors.Orange
            });
            verticalStack.Add(new SearchBar {
                Placeholder = "Placeholder"
            });
            verticalStack.Add(new SearchBar {
                HorizontalTextAlignment = TextAlignment.End, Text = "SearchBar HorizontalTextAlignment"
            });
            verticalStack.Add(new SearchBar {
                Text = "SearchBar MaxLength", MaxLength = 50
            });
            verticalStack.Add(new SearchBar {
                Text = "SearchBar CancelButtonColor", CancelButtonColor = Colors.IndianRed
            });

            var monkeyList = new List <string>
            {
                "Baboon",
                "Capuchin Monkey",
                "Blue Monkey",
                "Squirrel Monkey",
                "Golden Lion Tamarin",
                "Howler Monkey",
                "Japanese Macaque"
            };

            var picker = new Picker {
                Title = "Select a monkey", TitleColor = Colors.Red, FontFamily = "Dokdo", HorizontalTextAlignment = TextAlignment.Center
            };

            picker.ItemsSource = monkeyList;
            verticalStack.Add(picker);

            verticalStack.Add(new Slider());
            verticalStack.Add(new Slider {
                MinimumTrackColor = Colors.Orange, MaximumTrackColor = Colors.Purple, ThumbColor = Colors.GreenYellow
            });
            verticalStack.Add(new Slider {
                ThumbImageSource = "dotnet_bot.png"
            });

            verticalStack.Add(new Stepper());
            verticalStack.Add(new Stepper {
                BackgroundColor = Colors.IndianRed
            });
            verticalStack.Add(new Stepper {
                Minimum = 0, Maximum = 10, Value = 5
            });

            verticalStack.Add(new Switch());
            verticalStack.Add(new Switch()
            {
                OnColor = Colors.Green
            });
            verticalStack.Add(new Switch()
            {
                ThumbColor = Colors.Yellow
            });
            verticalStack.Add(new Switch()
            {
                OnColor = Colors.Green, ThumbColor = Colors.Yellow
            });

            verticalStack.Add(new DatePicker());
            verticalStack.Add(new DatePicker {
                TextColor = Colors.OrangeRed
            });
            verticalStack.Add(new DatePicker {
                CharacterSpacing = 6
            });
            verticalStack.Add(new DatePicker {
                FontSize = 24
            });

            verticalStack.Add(new TimePicker());
            verticalStack.Add(new TimePicker {
                TextColor = Colors.LightGreen
            });
            verticalStack.Add(new TimePicker {
                Time = TimeSpan.FromHours(8), CharacterSpacing = 6
            });

            verticalStack.Add(new Label {
                Text = "IMAGES (static | animated):"
            });
            verticalStack.Add(CreateImagesGrid());

            Content = new ScrollView
            {
                Content = verticalStack
            };
        }