protected void CombineByShader() { SkinnedMeshCombiner.CombineInstance combineInstance; for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++) { combinedMaterialList.Add(umaData.atlasList.atlas[atlasIndex].materialSample); for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.mesh = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.sharedMesh; combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount]; for (int i = 0; i < combineInstance.mesh.subMeshCount; i++) { combineInstance.destMesh[i] = -1; } combineInstance.bones = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.bones; combineInstance.destMesh[umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.subMeshIndex] = atlasIndex; combinedMeshList.Add(combineInstance); } } }
void CombineByShader() { SkinnedMeshCombiner.CombineInstance combineInstance; for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++) { combinedMaterialList.Add(umaData.atlasList.atlas[atlasIndex].materialSample); for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.destMesh = new int[1]; combineInstance.mesh = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.sharedMesh; combineInstance.bones = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.bones; combineInstance.destMesh[0] = atlasIndex; combinedMeshList.Add(combineInstance); } } }
//private void FireSlotAtlasNotification(UMAData umaData, Material[] materials) //{ // for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++) // { // for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++) // { // var materialDefinition = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex]; // var slotData = materialDefinition.source.slotData; // if (slotData.SlotAtlassed != null) // { // slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion); // } // } // } // SlotData[] slots = umaData.umaRecipe.slotDataList; // for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++) // { // var slotData = slots[slotIndex]; // if (slotData == null) continue; // if (slotData.textureNameList.Length == 1 && string.IsNullOrEmpty(slotData.textureNameList[0])) // { // if (slotData.SlotAtlassed != null) // { // slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion); // } // } // } //} protected void BuildCombineInstances() { SkinnedMeshCombiner.CombineInstance combineInstance; for (int materialIndex = 0; materialIndex < umaData.generatedMaterials.materials.Count; materialIndex++) { var generatedMaterial = umaData.generatedMaterials.materials[materialIndex]; combinedMaterialList.Add(generatedMaterial.material); for (int materialDefinitionIndex = 0; materialDefinitionIndex < generatedMaterial.materialFragments.Count; materialDefinitionIndex++) { var materialDefinition = generatedMaterial.materialFragments[materialDefinitionIndex]; var slotData = materialDefinition.slotData; combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.meshData = slotData.asset.meshData; combineInstance.targetSubmeshIndices = new int[combineInstance.meshData.subMeshCount]; for (int i = 0; i < combineInstance.meshData.subMeshCount; i++) { combineInstance.targetSubmeshIndices[i] = -1; } combineInstance.targetSubmeshIndices[slotData.asset.subMeshIndex] = materialIndex; combinedMeshList.Add(combineInstance); if (slotData.asset.SlotAtlassed != null) { slotData.asset.SlotAtlassed.Invoke(umaData, slotData, generatedMaterial.material, materialDefinition.atlasRegion); } } } }
protected void CombineByMaterial() { SlotData[] slots = umaData.umaRecipe.slotDataList; bool[] shareMaterial = new bool[slots.Length]; SkinnedMeshCombiner.CombineInstance combineInstance; int indexCount = 0; for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++) { if (slots[slotIndex] != null) { if (!shareMaterial[slotIndex]) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.mesh = slots[slotIndex].meshRenderer.sharedMesh; combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount]; for (int i = 0; i < combineInstance.mesh.subMeshCount; i++) { combineInstance.destMesh[i] = -1; } combineInstance.bones = slots[slotIndex].meshRenderer.bones; combineInstance.destMesh[slots[slotIndex].subMeshIndex] = indexCount; combinedMeshList.Add(combineInstance); Material tempMaterial = Instantiate(slots[slotIndex].materialSample) as Material; tempMaterial.name = slots[slotIndex].slotName; for (int textureType = 0; textureType < textureNameList.Length; textureType++) { if (tempMaterial.HasProperty(textureNameList[textureType])) { slots[slotIndex].GetOverlay(0).textureList[textureType].filterMode = FilterMode.Bilinear; tempMaterial.SetTexture(textureNameList[textureType], slots[slotIndex].GetOverlay(0).textureList[textureType]); } } combinedMaterialList.Add(tempMaterial); shareMaterial[slotIndex] = true; for (int slotIndex2 = slotIndex; slotIndex2 < slots.Length; slotIndex2++) { if (slots[slotIndex2] != null) { if (slotIndex2 != slotIndex && !shareMaterial[slotIndex2]) { if (slots[slotIndex].GetOverlay(0).textureList[0].name == slots[slotIndex2].GetOverlay(0).textureList[0].name) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.mesh = slots[slotIndex2].meshRenderer.sharedMesh; combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount]; for (int i = 0; i < combineInstance.mesh.subMeshCount; i++) { combineInstance.destMesh[i] = -1; } combineInstance.bones = slots[slotIndex2].meshRenderer.bones; combineInstance.destMesh[slots[slotIndex2].subMeshIndex] = indexCount; combinedMeshList.Add(combineInstance); shareMaterial[slotIndex2] = true; } } } } indexCount++; } } else { shareMaterial[slotIndex] = true; } } }
void CombineByMaterial() { DKSlotData[] slots = umaData.umaRecipe.slotDataList; bool[] shareMaterial = new bool[slots.Length]; SkinnedMeshCombiner.CombineInstance combineInstance; int indexCount = 0; for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++) { if (slots[slotIndex] != null) { if (!shareMaterial[slotIndex]) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.destMesh = new int[1]; combineInstance.mesh = slots[slotIndex].meshRenderer.sharedMesh; combineInstance.bones = slots[slotIndex].meshRenderer.bones; combineInstance.destMesh[0] = indexCount; combinedMeshList.Add(combineInstance); Material tempMaterial = Instantiate(slots[slotIndex].materialSample) as Material; tempMaterial.name = slots[slotIndex].slotName; for (int textureType = 0; textureType < textureNameList.Length; textureType++) { if (tempMaterial.HasProperty(textureNameList[textureType])) { slots[slotIndex].overlayList[0].textureList[textureType].filterMode = FilterMode.Bilinear; tempMaterial.SetTexture(textureNameList[textureType], slots[slotIndex].overlayList[0].textureList[textureType]); } } combinedMaterialList.Add(tempMaterial); shareMaterial[slotIndex] = true; for (int slotIndex2 = slotIndex; slotIndex2 < slots.Length; slotIndex2++) { if (slots[slotIndex2] != null) { if (slotIndex2 != slotIndex && !shareMaterial[slotIndex2]) { if (slots[slotIndex].overlayList[0].textureList[0].name == slots[slotIndex2].overlayList[0].textureList[0].name) { combineInstance = new SkinnedMeshCombiner.CombineInstance(); combineInstance.destMesh = new int[1]; combineInstance.mesh = slots[slotIndex2].meshRenderer.sharedMesh; combineInstance.bones = slots[slotIndex2].meshRenderer.bones; combineInstance.destMesh[0] = indexCount; combinedMeshList.Add(combineInstance); shareMaterial[slotIndex2] = true; } } } } indexCount++; } } else { shareMaterial[slotIndex] = true; } } }