public static Folder AppendCollisionAssets(UserAvatar avatar, string avatarType) { Folder collisionAssets; if (DEBUG_RAPID_ASSEMBLY) { collisionAssets = new Folder(); } else { collisionAssets = AppendCharacterAssets(avatar, avatarType, "COLLISION"); } // Replace the head mesh with a low-poly head DataModelMesh oldHeadMesh = collisionAssets.FindFirstChildOfClass <DataModelMesh>(); if (oldHeadMesh != null) { oldHeadMesh.Destroy(); } _ = new SpecialMesh() { MeshId = "rbxassetid://582002794", MeshType = MeshType.FileMesh, Scale = new Vector3(1, 1, 1), Offset = new Vector3(), Parent = collisionAssets }; return(collisionAssets); }
public static void OverwriteHead(DataModelMesh mesh, BasePart head) { Contract.Requires(mesh != null && head != null); DataModelMesh currentMesh = head.FindFirstChild <DataModelMesh>("Mesh"); if (currentMesh != null) { currentMesh.Destroy(); } mesh.Name = "Mesh"; mesh.Parent = head; // Apply Rthro adjustments Vector3Value[] overrides = mesh.GetChildrenOfType <Vector3Value>(); foreach (Vector3Value overrider in overrides) { Attachment attachment = head.FindFirstChild <Attachment>(overrider.Name); if (attachment != null) { CFrame cf = attachment.CFrame; attachment.CFrame = new CFrame(overrider.Value) * (cf - cf.Position); } } // Move any extra instances into the Head. var extraInstances = mesh.GetChildren() .Except(overrides) .ToList(); extraInstances.ForEach((inst) => inst.Parent = head); }
public static void OverwriteHead(Instance asset, Part head) { DataModelMesh mesh = (DataModelMesh)asset; DataModelMesh currentMesh = head.FindFirstChild <DataModelMesh>("Mesh"); if (currentMesh != null) { currentMesh.Destroy(); } mesh.Name = "Mesh"; mesh.Parent = head; }
public static Asset ResolveHeadMeshAsset(DataModelMesh mesh) { Contract.Requires(mesh != null); string result = "Default"; if (mesh is BevelMesh) { BevelMesh bevelMesh = mesh as BevelMesh; BevelType bevelType = BevelType.Unknown; if (mesh is BlockMesh) { bevelType = BevelType.Block; } else if (mesh is CylinderMesh) { bevelType = BevelType.Cylinder; } Head match = Lookup.Keys .Where((head) => bevelType == head.BevelType) .Where((head) => head.FieldsMatchWith(bevelMesh)) .First(); if (match != null) { result = Lookup[match]; } mesh.Scale = new Vector3(1, 1, 1); } else if (mesh is SpecialMesh) { SpecialMesh specialMesh = mesh as SpecialMesh; if (specialMesh.MeshType == MeshType.Sphere) { result = "Perfection"; specialMesh.Scale = new Vector3(1, 1, 1); } } if (result == "Default") { mesh.Scale /= new Vector3(1.25f, 1.25f, 1.25f); } return(Asset.FromResource("Meshes/Heads/" + result + ".mesh")); }
public static Mesh BakePart(Part part, Material material = null) { Mesh result = null; Asset meshAsset = null; Asset textureAsset = null; Vector3 scale = null; CFrame offset = null; if (material != null) { material.LinkedTo = part; material.Transparency = part.Transparency; material.Reflectance = part.Reflectance; } if (part.Transparency < 1) { if (part.IsA("MeshPart")) { MeshPart meshPart = (MeshPart)part; if (meshPart.MeshID == null) { string partName = meshPart.Name; if (StandardLimbs.ContainsKey(partName)) { meshAsset = StandardLimbs[partName]; } } else { meshAsset = Asset.GetByAssetId(meshPart.MeshID); } if (meshPart.TextureID != null) { textureAsset = Asset.GetByAssetId(meshPart.TextureID); } scale = meshPart.Size / meshPart.InitialSize; offset = part.CFrame; } else { offset = part.CFrame; SpecialMesh specialMesh = part.FindFirstChildOfClass <SpecialMesh>(); if (specialMesh != null && specialMesh.MeshType == MeshType.FileMesh) { meshAsset = Asset.GetByAssetId(specialMesh.MeshId); scale = specialMesh.Scale; offset *= new CFrame(specialMesh.Offset); if (material != null) { textureAsset = Asset.GetByAssetId(specialMesh.TextureId); material.VertexColor = specialMesh.VertexColor; } } else { DataModelMesh legacy = part.FindFirstChildOfClass <DataModelMesh>(); if (legacy != null) { meshAsset = Head.ResolveHeadMeshAsset(legacy); scale = legacy.Scale; offset *= new CFrame(legacy.Offset); } } } } else { // Just give it a blank mesh to eat for now. result = new Mesh(); } if (meshAsset != null) { if (material != null) { material.TextureAsset = textureAsset; } result = FromAsset(meshAsset); result.BakeGeometry(scale, offset); } return(result); }
public static Mesh BakePart(BasePart part, ValveMaterial material = null) { Contract.Requires(part != null); Mesh result = null; Asset meshAsset = null; Asset textureAsset = null; Vector3 scale = null; CFrame offset = null; if (material != null) { material.LinkedTo = part; material.Reflectance = part.Reflectance; material.Transparency = part.Transparency; } if (part.Transparency < 1) { if (part is MeshPart meshPart) { string meshId = meshPart.MeshId; if (meshId != null && meshId.Length > 0) { meshAsset = Asset.GetByAssetId(meshId); } else { string partName = meshPart.Name; StandardLimbs.TryGetValue(partName, out meshAsset); } if (meshPart.TextureID != null) { textureAsset = Asset.GetByAssetId(meshPart.TextureID); } scale = meshPart.Size / meshPart.InitialSize; offset = part.CFrame; } else { SpecialMesh specialMesh = part.FindFirstChildOfClass <SpecialMesh>(); offset = part.CFrame; if (specialMesh != null && specialMesh.MeshType == MeshType.FileMesh) { meshAsset = Asset.GetByAssetId(specialMesh.MeshId); offset *= new CFrame(specialMesh.Offset); scale = specialMesh.Scale; if (material != null) { textureAsset = Asset.GetByAssetId(specialMesh.TextureId); material.VertexColor = specialMesh.VertexColor; } } else { DataModelMesh legacy = part.FindFirstChildOfClass <DataModelMesh>(); if (legacy != null) { meshAsset = Head.ResolveHeadMeshAsset(legacy); offset *= new CFrame(legacy.Offset); scale = legacy.Scale; } } } } else { // Just give it a blank mesh to eat for now. result = new Mesh(); } if (meshAsset != null) { if (material != null) { material.TextureAsset = textureAsset; } result = FromAsset(meshAsset); result.BakeGeometry(scale, offset); } return(result); }