private static Entity CreateTrackingEntity(EntityAsset entityAsset, Entity rootEntityAsset, ModelAsset modelAsset, string nodeName) { var childEntity = new Entity { Name = nodeName }; // Add TransformComponent childEntity.Add(TransformComponent.Key, new TransformComponent()); // Add ModelNodeLinkComponent childEntity.Add(ModelNodeLinkComponent.Key, new ModelNodeLinkComponent { NodeName = nodeName, Target = rootEntityAsset.Get(ModelComponent.Key), }); // Add this asset to the list entityAsset.Hierarchy.Entities.Add(childEntity); // Get or create transformation component var transformationComponent = rootEntityAsset.GetOrCreate(TransformComponent.Key); // Mark node as preserved modelAsset.PreserveNodes(new List <string> { nodeName }); // Add as children of model entity transformationComponent.Children.Add(childEntity.GetOrCreate(TransformComponent.Key)); return(childEntity); }
private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName) { 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 foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key, null)); if (foundMaterial != null) { asset.Materials.Add(new ModelMaterial { Name = material.Key, MaterialInstance = new MaterialInstance() { Material = AttachedReferenceManager.CreateSerializableVersion <Material>(foundMaterial.Id, foundMaterial.Location) } }); } } //handle the case where during import we imported no materials at all //todo Instead of null material add a default paradox material if (entityInfo.Materials.Count == 0) { asset.Materials.Add(new ModelMaterial { Name = "Material", MaterialInstance = new MaterialInstance() }); } } if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) { asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var modelUrl = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": ""), null); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo) { var frontAxis = Vector3.Cross(entityInfo.UpAxis, Vector3.UnitZ).Length() < MathUtil.ZeroTolerance ? Vector3.UnitY : Vector3.UnitZ; var asset = new ModelAsset { Source = assetSource, UpAxis = entityInfo.UpAxis, FrontAxis = frontAxis }; if (entityInfo.Models != null) { var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList(); foreach (var model in entityInfo.Models) { var meshParams = new MeshMaterialParameters { Parameters = model.Parameters, NodeName = model.NodeName }; var matId = model.MaterialName; var matName = GenerateFinalMaterialName(localPath, matId); var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(matName, null)); if (foundMaterial != null) { var matReference = new AssetReference <MaterialAsset>(foundMaterial.Id, foundMaterial.Location); meshParams.Material = matReference; } asset.MeshParameters.Add(model.MeshName, meshParams); } } if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) { asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var modelUrl = new UFile(localPath.GetFileName() + "_model", null); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static Entity CreateTrackingEntity(EntityAsset entityAsset, Entity rootEntityAsset, ModelAsset modelAsset, string nodeName) { var childEntity = new Entity { Name = nodeName }; // Add TransformComponent childEntity.Add(TransformComponent.Key, new TransformComponent()); // Add ModelNodeLinkComponent childEntity.Add(ModelNodeLinkComponent.Key, new ModelNodeLinkComponent { NodeName = nodeName, Target = rootEntityAsset.Get(ModelComponent.Key), }); // Add this asset to the list entityAsset.Hierarchy.Entities.Add(childEntity); // Get or create transformation component var transformationComponent = rootEntityAsset.GetOrCreate(TransformComponent.Key); // Mark node as preserved modelAsset.PreserveNodes(new List<string> { nodeName }); // Add as children of model entity transformationComponent.Children.Add(childEntity.GetOrCreate(TransformComponent.Key)); return childEntity; }
private static AssetItem ImportModel(List<AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName) { 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 foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key, null)); if (foundMaterial != null) asset.Materials.Add(new ModelMaterial { Name = material.Key, MaterialInstance = new MaterialInstance() { Material = AttachedReferenceManager.CreateSerializableVersion<Material>(foundMaterial.Id, foundMaterial.Location) } }); } } if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) asset.PreserveNodes(entityInfo.AnimationNodes); var modelUrl = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": ""), null); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return assetItem; }