public static bool HasNode(this IILayer layer, IINode node, bool checkInChild = true) { #if MAX2020 ITab <IINode> nodes = Loader.Global.INodeTab.Create(); #else ITab <IINode> nodes = Loader.Global.INodeTabNS.Create(); #endif IILayerProperties layerProperties = Loader.IIFPLayerManager.GetLayer(layer.Name); layerProperties.Nodes(nodes); foreach (IINode n in Tools.ITabToIEnumerable(nodes)) { if (node.Handle == n.Handle) { return(true); } } for (int i = 0; i < layer.NumOfChildLayers; i++) { IILayer child = layer.GetChildLayer(i); if (child.HasNode(node, checkInChild)) { return(true); } } return(false); }
public static IEnumerable <IINode> LayerNodes(this IILayer layer) { IILayerProperties layerProp = Loader.IIFPLayerManager.GetLayer(layer.Name); #if MAX2020 ITab <IINode> nodes = Loader.Global.INodeTab.Create(); #else ITab <IINode> nodes = Loader.Global.INodeTabNS.Create(); #endif layerProp.Nodes(nodes); return(Tools.ITabToIEnumerable(nodes)); }
private BabylonNode ExportMesh(IIGameScene scene, IIGameNode meshNode, BabylonScene babylonScene) { if (IsMeshExportable(meshNode) == false) { return(null); } RaiseMessage(meshNode.Name, 1); // Instances #if MAX2020 var tabs = Loader.Global.INodeTab.Create(); #else var tabs = Loader.Global.NodeTab.Create(); #endif Loader.Global.IInstanceMgr.InstanceMgr.GetInstances(meshNode.MaxNode, tabs); if (tabs.Count > 1) { foreach (IINode instanceNode in Tools.ITabToIEnumerable(tabs)) { //this make sure every instance node is indexed in guid dictionary Tools.GetGuid(instanceNode); } // For a mesh with instances, we distinguish between master and instance meshes: // - a master mesh stores all the info of the mesh (transform, hierarchy, animations + vertices, indices, materials, bones...) // - an instance mesh only stores the info of the node (transform, hierarchy, animations) // Check if this mesh has already been exported List <BabylonMesh> babylonMasterMeshes = new List <BabylonMesh>(); var index = 0; while (index < tabs.Count) { #if MAX2017 || MAX2018 || MAX2019 || MAX2020 var tab = tabs[index]; #else var tab = tabs[new IntPtr(index)]; #endif Guid nodeGuid = Tools.guids.FirstOrDefault(x => x.Value == tab).Key; babylonMasterMeshes.AddRange(babylonScene.MeshesList.FindAll(_babylonMesh => { // Same id return(_babylonMesh.id == nodeGuid.ToString() && // Mesh is not a dummy _babylonMesh.isDummy == false); })); index++; } if (babylonMasterMeshes.Count > 0) { // Mesh already exported // Export this node as instance // Check if we need to export this instance as an instance mesh. // If there is already an exported mesh in the scene that shares this mesh's material, then export it as an instance. BabylonMesh babylonMasterMesh = null; foreach (var mesh in babylonMasterMeshes) { if (mesh.materialId == null || (meshNode.NodeMaterial != null && meshNode.NodeMaterial.MaxMaterial.GetGuid().ToString().Equals(mesh.materialId))) { babylonMasterMesh = mesh; } } if (babylonMasterMesh != null) { return(ExportInstanceMesh(scene, meshNode, babylonScene, babylonMasterMesh)); } return(ExportMasterMesh(scene, meshNode, babylonScene)); } } return(ExportMasterMesh(scene, meshNode, babylonScene)); }