private Texture2D LoadTexture(int textureIndex) { var texture = data.gltf.Textures[textureIndex]; var ddsExtension = ExtensionUtil.LoadExtension <glTFLoader.Schema.Msft_texture_ddsExtension>(texture.Extensions, "MSFT_texture_dds"); if (ddsExtension != null && ddsExtension.Source.HasValue) { return(LoadDdsTexture(ddsExtension.Source.Value, texture.Sampler)); } else if (texture.Source.HasValue) { return(LoadImageTexture(texture.Source.Value, texture.Sampler)); } return(null); }
public void LoadNode(int nodeIndex, Transform parent) { var node = data.gltf.Nodes[nodeIndex]; // Create object for node var name = string.IsNullOrEmpty(node.Name) ? $"Node{nodeIndex}" : node.Name; var obj = new GameObject(name); var transform = obj.transform; transform.SetParent(parent); data.cache.nodes[nodeIndex] = obj; // Set object transform var matrix = GetNodeMatrix(node); transform.localPosition = matrix.GetPosition(); transform.localRotation = matrix.GetRotation(); transform.localScale = matrix.GetScale(); var meshIndex = node.Mesh; if (meshIndex.HasValue) { meshLoader.LoadMeshAndMaterials(meshIndex.Value, node.Skin, obj); } var colliderExtension = ExtensionUtil.LoadExtension <Unity_collidersNodeExtension>(node.Extensions, "Unity_colliders"); if (colliderExtension != null) { colliderLoader.LoadCollider(colliderExtension.Collider.Value, obj); } // Recursively load child nodes var childNodeIndices = node.Children; if (childNodeIndices != null) { foreach (var childNodeIndex in childNodeIndices) { LoadNode(childNodeIndex, transform); } } }
public void LoadCollider(int colliderIndex, GameObject obj) { var colliderExtension = ExtensionUtil.LoadExtension <Unity_collidersGltfExtension>(data.gltf.Extensions, "Unity_colliders"); var collider = colliderExtension.Colliders[colliderIndex]; if (collider.BoxCollider != null) { LoadBoxCollider(collider.BoxCollider, obj); } else if (collider.SphereCollider != null) { LoadSphereCollider(collider.SphereCollider, obj); } else if (collider.CapsuleCollider != null) { LoadCapsuleCollider(collider.CapsuleCollider, obj); } else if (collider.MeshCollider != null) { LoadMeshCollider(collider.MeshCollider, obj); } }
private void LoadEmissiveMap(glTFLoader.Schema.Material material, Material unityMaterial) { var emissiveTexture = material.EmissiveTexture; if (emissiveTexture != null || material.ShouldSerializeEmissiveFactor()) { // Strength var strengthExtension = ExtensionUtil.LoadExtension <glTFLoader.Schema.Khr_materials_emissive_strength>(material.Extensions, "KHR_materials_emissive_strength"); var strength = strengthExtension != null ? strengthExtension.EmissiveStrength : 1f; // Factor var factor = TypeConverter.ConvertColor(material.EmissiveFactor); unityMaterial.SetColor("_EmissionColor", factor * strength); // Texture if (emissiveTexture != null) { var texture = textureLoader.LoadTexture(emissiveTexture.Index, false); unityMaterial.SetTexture("_EmissionMap", texture); } unityMaterial.EnableKeyword("_EMISSION"); } }