public override void meshAssign_UV0(int channel, MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Vector2[] uvs, float[] sliceIndexes) { if (textureBakeResults.resultType == MB2_TextureBakeResults.ResultType.atlas) { mesh.uv = uvs; } else { { if (uvs.Length == sliceIndexes.Length) { List <Vector3> nuvs = new List <Vector3>(); for (int i = 0; i < uvs.Length; i++) { nuvs.Add(new Vector3(uvs[i].x, uvs[i].y, sliceIndexes[i])); } mesh.SetUVs(0, nuvs); } else { Debug.LogError("UV slice buffer was not the same size as the uv buffer"); } } } }
internal void CopyVertsNormsTansToBuffers(MB_DynamicGameObject dgo, MB_IMeshBakerSettings settings, int vertsIdx, Vector3[] nnorms, Vector4[] ntangs, Vector3[] nverts, Vector3[] normals, Vector4[] tangents, Vector3[] verts) { bool isMeshRenderer = dgo.gameObject.GetComponent <Renderer>() is MeshRenderer; if (settings.smrNoExtraBonesWhenCombiningMeshRenderers && isMeshRenderer && dgo._tmpSMR_CachedBones[0] != dgo.gameObject.transform // bone may not have a parent ancestor that is a bone ) { // transform all the verticies, norms and tangents into the parent bone's local space (adjusted by the parent bone's bind pose). // there should be only one bone and bind pose for a mesh renderer dgo. // The bone and bind pose should be the parent-bone's NOT the MeshRenderers. Matrix4x4 l2parentMat = dgo._tmpSMR_CachedBindposes[0].inverse * dgo._tmpSMR_CachedBones[0].worldToLocalMatrix * dgo.gameObject.transform.localToWorldMatrix; // Similar to local2world but with translation removed and we are using the inverse transpose. // We use this for normals and tangents because it handles scaling correctly. Matrix4x4 l2parentRotScale = l2parentMat; l2parentRotScale[0, 3] = l2parentRotScale[1, 3] = l2parentRotScale[2, 3] = 0f; l2parentRotScale = l2parentRotScale.inverse.transpose; //can't modify the arrays we get from the cache because they will be modified multiple times if the same mesh is being added multiple times. for (int j = 0; j < nverts.Length; j++) { int vIdx = vertsIdx + j; verts[vertsIdx + j] = l2parentMat.MultiplyPoint3x4(nverts[j]); if (settings.doNorm) { normals[vIdx] = l2parentRotScale.MultiplyPoint3x4(nnorms[j]).normalized; } if (settings.doTan) { float w = ntangs[j].w; //need to preserve the w value tangents[vIdx] = l2parentRotScale.MultiplyPoint3x4(((Vector3)ntangs[j])).normalized; tangents[vIdx].w = w; } } } else { if (settings.doNorm) { nnorms.CopyTo(normals, vertsIdx); } if (settings.doTan) { ntangs.CopyTo(tangents, vertsIdx); } nverts.CopyTo(verts, vertsIdx); } }
public void DrawGUI(MB_IMeshBakerSettings momm, bool settingsEnabled) { EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); GUI.enabled = settingsEnabled; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doNorm, gc_doNormGUIContent); EditorGUILayout.PropertyField(doTan, gc_doTanGUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV, gc_doUVGUIContent); EditorGUILayout.PropertyField(doUV3, gc_doUV3GUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV4, gc_doUV4GUIContent); EditorGUILayout.PropertyField(doCol, gc_doColGUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(doBlendShapes, gc_doBlendShapeGUIContent); if (momm.lightmapOption == MB2_LightmapOptions.preserve_current_lightmapping) { if (MBVersion.GetMajorVersion() == 5) { EditorGUILayout.HelpBox("The best choice for Unity 5 is to Ignore_UV2 or Generate_New_UV2 layout. Unity's baked GI will create the UV2 layout it wants. See manual for more information.", MessageType.Warning); } } if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout) { EditorGUILayout.HelpBox("Generating new lightmap UVs can split vertices which can push the number of vertices over the 64k limit.", MessageType.Warning); } EditorGUILayout.PropertyField(lightmappingOption, gc_lightmappingOptionGUIContent); if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout) { EditorGUILayout.PropertyField(uv2OutputParamsHardAngle, gc_uv2HardAngleGUIContent); EditorGUILayout.PropertyField(uv2OutputParamsPackingMargin, gc_uv2PackingMarginUV3GUIContent); EditorGUILayout.Separator(); } EditorGUILayout.PropertyField(renderType, gc_renderTypeGUIContent); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(clearBuffersAfterBake, gc_clearBuffersAfterBakeGUIContent); EditorGUILayout.PropertyField(centerMeshToBoundsCenter, gc_CenterMeshToBoundsCenter); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(optimizeAfterBake, gc_OptimizeAfterBake); GUI.enabled = true; EditorGUILayout.EndVertical(); }
void _CopySettings(MB_IMeshBakerSettings src, MB_IMeshBakerSettings targ) { targ.clearBuffersAfterBake = src.clearBuffersAfterBake; targ.doBlendShapes = src.doBlendShapes; targ.doCol = src.doCol; targ.doNorm = src.doNorm; targ.doTan = src.doTan; targ.doUV = src.doUV; targ.doUV3 = src.doUV3; targ.doUV4 = src.doUV4; targ.optimizeAfterBake = src.optimizeAfterBake; targ.recenterVertsToBoundsCenter = src.recenterVertsToBoundsCenter; targ.lightmapOption = src.lightmapOption; targ.renderType = src.renderType; targ.uv2UnwrappingParamsHardAngle = src.uv2UnwrappingParamsHardAngle; targ.uv2UnwrappingParamsPackMargin = src.uv2UnwrappingParamsPackMargin; }
void _CopySettings(MB_IMeshBakerSettings src, MB_IMeshBakerSettings targ) { targ.clearBuffersAfterBake = src.clearBuffersAfterBake; targ.doBlendShapes = src.doBlendShapes; targ.doCol = src.doCol; targ.doNorm = src.doNorm; targ.doTan = src.doTan; targ.doUV = src.doUV; targ.doUV3 = src.doUV3; targ.doUV4 = src.doUV4; targ.doUV5 = src.doUV5; targ.doUV6 = src.doUV6; targ.doUV7 = src.doUV7; targ.doUV8 = src.doUV8; targ.optimizeAfterBake = src.optimizeAfterBake; targ.pivotLocationType = src.pivotLocationType; targ.lightmapOption = src.lightmapOption; targ.renderType = src.renderType; targ.uv2UnwrappingParamsHardAngle = src.uv2UnwrappingParamsHardAngle; targ.uv2UnwrappingParamsPackMargin = src.uv2UnwrappingParamsPackMargin; }
public virtual void meshAssign_UV0(int channel, MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Vector2[] uvs, float[] sliceIndexes) { mesh.uv = uvs; }
public static void DefaultDelegateAssignMeshColors(MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Color[] colors, float[] sliceIndexes) { mesh.colors = colors; }
public virtual void meshAssign_colors(MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Color[] colors, float[] sliceIndexes) { mesh.colors = colors; }
public virtual void meshAssign_UV8(int channel, MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Vector2[] uvs, float[] sliceIndexes) { #if UNITY_2018_2_OR_NEWER mesh.uv8 = uvs; #endif }
public void DrawGUI(MB_IMeshBakerSettings momm, bool settingsEnabled, bool doingTextureArrays) { EditorGUILayout.BeginVertical(editorStyles.editorBoxBackgroundStyle); GUI.enabled = settingsEnabled; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doNorm, gc_doNormGUIContent); EditorGUILayout.PropertyField(doTan, gc_doTanGUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV, gc_doUVGUIContent); EditorGUILayout.PropertyField(doUV3, gc_doUV3GUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV4, gc_doUV4GUIContent); EditorGUILayout.PropertyField(doUV5, gc_doUV5GUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV6, gc_doUV6GUIContent); EditorGUILayout.PropertyField(doUV7, gc_doUV7GUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(doUV8, gc_doUV8GUIContent); EditorGUILayout.PropertyField(doCol, gc_doColGUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(doBlendShapes, gc_doBlendShapeGUIContent); if (momm.lightmapOption == MB2_LightmapOptions.preserve_current_lightmapping) { if (MBVersion.GetMajorVersion() == 5) { EditorGUILayout.HelpBox("The best choice for Unity 5 is to Ignore_UV2 or Generate_New_UV2 layout. Unity's baked GI will create the UV2 layout it wants. See manual for more information.", MessageType.Warning); } } if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout) { EditorGUILayout.HelpBox("Generating new lightmap UVs can split vertices which can push the number of vertices over the 64k limit.", MessageType.Warning); } EditorGUILayout.PropertyField(lightmappingOption, gc_lightmappingOptionGUIContent); if (momm.lightmapOption == MB2_LightmapOptions.generate_new_UV2_layout) { EditorGUILayout.PropertyField(uv2OutputParamsHardAngle, gc_uv2HardAngleGUIContent); EditorGUILayout.PropertyField(uv2OutputParamsPackingMargin, gc_uv2PackingMarginUV3GUIContent); EditorGUILayout.Separator(); } UnityEngine.Object obj = null; obj = assignToMeshCustomizer.objectReferenceValue; EditorGUILayout.PropertyField(renderType, gc_renderTypeGUIContent); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(clearBuffersAfterBake, gc_clearBuffersAfterBakeGUIContent); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(pivotLocationType, gc_PivotLocationType); if (pivotLocationType.enumValueIndex == (int)MB_MeshPivotLocation.customLocation) { EditorGUILayout.PropertyField(pivotLocation, gc_PivotLocation); } EditorGUILayout.PropertyField(optimizeAfterBake, gc_OptimizeAfterBake); EditorGUILayout.Space(); EditorGUILayout.LabelField("Advanced", EditorStyles.boldLabel); // Don't use a PropertyField because we may not be able to use the assigned object. It may not implement requried interface. if (doingTextureArrays && assignToMeshCustomizer.objectReferenceValue == null) { EditorGUILayout.HelpBox("The Textures were baked into Texture Arrays. You probaly need to a customizer here" + " to embed the slice index in the mesh. You can use one of the included customizers or write your own. " + "See the example customizers in MeshBaker/Scripts/AssignToMeshCustomizers.", MessageType.Error); } obj = EditorGUILayout.ObjectField(gc_AssignMeshCusomizer, obj, typeof(UnityEngine.Object), true); if (obj == null || !(obj is IAssignToMeshCustomizer)) { assignToMeshCustomizer.objectReferenceValue = null; } else { assignToMeshCustomizer.objectReferenceValue = obj; } GUI.enabled = true; EditorGUILayout.EndVertical(); }