Esempio n. 1
0
        private static ModelMaterial AttachId(ModelMaterial modelMaterial)
        {
            // Compute an id for the list item based on the name of the material
            var materialNameKey = modelMaterial.Name;
            var modelMaterialId = ObjectId.FromBytes(Encoding.UTF8.GetBytes(materialNameKey)).ToGuid();

            IdentifiableHelper.SetId(modelMaterial, modelMaterialId);
            return(modelMaterial);
        }
Esempio n. 2
0
        private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName, AssetItem skeletonAsset)
        {
            var asset = new ModelAsset {
                Source = assetSource
            };

            if (entityInfo.Models != null)
            {
                var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList();
                foreach (var material in entityInfo.Materials)
                {
                    var modelMaterial = new ModelMaterial
                    {
                        Name             = material.Key,
                        MaterialInstance = new MaterialInstance()
                    };
                    var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key));
                    if (foundMaterial != null)
                    {
                        var reference = AttachedReferenceManager.CreateProxyObject <Material>(foundMaterial.Id, foundMaterial.Location);
                        modelMaterial.MaterialInstance.Material = reference;
                    }
                    //todo Instead of null material add a default xenko material
                    asset.Materials.Add(AttachId(modelMaterial));
                }
                //handle the case where during import we imported no materials at all
                //todo Instead of null material add a default xenko material
                if (entityInfo.Materials.Count == 0)
                {
                    var modelMaterial = new ModelMaterial {
                        Name = "Material", MaterialInstance = new MaterialInstance()
                    };
                    asset.Materials.Add(AttachId(modelMaterial));
                }
            }

            if (skeletonAsset != null)
            {
                asset.Skeleton = AttachedReferenceManager.CreateProxyObject <Skeleton>(skeletonAsset.Id, skeletonAsset.Location);
            }

            var modelUrl  = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": ""));
            var assetItem = new AssetItem(modelUrl, asset);

            assetReferences.Add(assetItem);
            return(assetItem);
        }
Esempio n. 3
0
        private static ModelMaterial AttachId(ModelMaterial modelMaterial)
        {
            // Compute an id for the list item based on the name of the material
            var materialNameKey = modelMaterial.Name;
            var modelMaterialId = ObjectId.FromBytes(Encoding.UTF8.GetBytes(materialNameKey)).ToGuid();

            IdentifiableHelper.SetId(modelMaterial, modelMaterialId);
            return modelMaterial;
        }
Esempio n. 4
0
        private static AssetItem ImportModel(List<AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName, AssetItem skeletonAsset)
        {
            var asset = new ModelAsset { Source = assetSource };

            if (entityInfo.Models != null)
            {
                var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList();
                foreach (var material in entityInfo.Materials)
                {
                    var modelMaterial = new ModelMaterial
                    {
                        Name = material.Key,
                        MaterialInstance = new MaterialInstance()
                    };
                    var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key));
                    if (foundMaterial != null)
                    {
                        var reference = AttachedReferenceManager.CreateProxyObject<Material>(foundMaterial.Id, foundMaterial.Location);
                        modelMaterial.MaterialInstance.Material = reference;
                    }
                    //todo Instead of null material add a default xenko material
                    asset.Materials.Add(AttachId(modelMaterial));
                }
                //handle the case where during import we imported no materials at all
                //todo Instead of null material add a default xenko material
                if (entityInfo.Materials.Count == 0)
                {
                    var modelMaterial = new ModelMaterial { Name = "Material", MaterialInstance = new MaterialInstance() };
                    asset.Materials.Add(AttachId(modelMaterial));
                }
            }

            if (skeletonAsset != null)
                asset.Skeleton = AttachedReferenceManager.CreateProxyObject<Skeleton>(skeletonAsset.Id, skeletonAsset.Location);

            var modelUrl = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": ""));
            var assetItem = new AssetItem(modelUrl, asset);
            assetReferences.Add(assetItem);
            return assetItem;
        }