/// <summary> /// Adds the mesh for all the components and their subcomponenets in the custom rigid group. <see cref="ExportAll(ComponentOccurrence,bool,bool,bool)"/> /// </summary> /// <param name="group">The group to export from</param> /// <param name="mesh">Mesh to store physics data in.</param> /// <returns>All the sufaces to export</returns> private List <SurfaceBody> GenerateExportList(CustomRigidGroup group, PhysicalProperties physics) { List <SurfaceBody> plannedExports = new List <SurfaceBody>(); // Calculate minimum volume to export a component double maxVolume = 0; foreach (ComponentOccurrence occ in group.occurrences) { double curVolume = Utilities.BoxVolume(occ.RangeBox); if (curVolume > maxVolume) { maxVolume = curVolume; } } double minVolume = maxVolume * MIN_VOLUME_PERCENT; // Analyze all component occurrences foreach (ComponentOccurrence occ in group.occurrences) { if (Utilities.BoxVolume(occ.RangeBox) >= minVolume) { GenerateExportList(occ, plannedExports, physics, minVolume); } } return(plannedExports); }
/// <summary> /// Creates an empty BXDA Mesh. /// </summary> public BXDAMesh(Guid guid) { GUID = guid; physics = new PhysicalProperties(); meshes = new List <BXDASubMesh>(); colliders = new List <BXDASubMesh>(); }
public DnDObject(ArmorClass ac, HitPoints hp, PhysicalProperties physicalProperties, Resistance resistance) { AC = ac; HP = hp; PhysicalProperties = physicalProperties; Resistance = resistance; }
void OnTriggerEnter(Collider collider) { if (collider.gameObject.Equals(gameObjectToVoxelise)) { return; } if (collider.rigidbody == null) { return; } PhysicalProperties gameObjectToVoxelisePP = gameObjectToVoxelise.GetComponent <PhysicalProperties>(); PhysicalProperties collidingPP = collider.gameObject.GetComponent <PhysicalProperties>(); RaycastHit willCollidePoint; Ray ray = new Ray(collider.transform.position, collider.rigidbody.velocity); Physics.Raycast(ray, out willCollidePoint); Rigidbody willCollideWith = willCollidePoint.rigidbody; if (!willCollideWith) { return; } //TODO does this ensure this rigidbody? Vector3 velocity1 = willCollideWith.velocity; Vector3 velocity2 = collider.rigidbody.velocity; float mass1 = willCollideWith.mass; float mass2 = collider.rigidbody.mass; Vector3 willCollideNormal = willCollidePoint.normal; willCollideNormal.Normalize(); willCollideNormal *= 2; float exertedForce = Vector3.Dot(willCollideNormal, (mass2 * velocity1 - mass1 * velocity2)) / (mass1 + mass2); exertedForce /= Time.fixedDeltaTime; Debug.Log(exertedForce); float aboveThreshold = gameObjectToVoxelisePP.doesBreak(exertedForce); if (aboveThreshold <= 0f) { return; } gameObjectToVoxelise.GetComponent <ThreadSafeDestructionDriver>().SplitDestroy(willCollidePoint.point, aboveThreshold, gameObjectToVoxelisePP); }
private PhysicalProperties ExportPhysicalProperties(MassProperties massProperties) { var physicalProperties = new PhysicalProperties(); physicalProperties.Mass = massProperties.Mass; // kg -> kg physicalProperties.Area = massProperties.Area / Math.Pow(100, 2); // cm^2 -> m^2 physicalProperties.Volume = massProperties.Volume / Math.Pow(100, 3); // cm^3 -> m^3 physicalProperties.CenterOfMass = GetVector3DConvertUnits(massProperties.CenterOfMass); return(physicalProperties); }
public static void WritePhysicalProperties(EndianAwareBinaryWriter writer, PhysicalProperties value) { writer.WriteByte((byte)(value.Enabled ? 1 : 0)); if (value.Enabled) { writer.WriteSingle(value.Density); writer.WriteSingle(value.Friction); writer.WriteSingle(value.Elasticity); writer.WriteSingle(value.FrictionWeight); writer.WriteSingle(value.ElasticityWeight); } }
public Dictionary <short, Fragment> Fragment(ThreadSafeVoxelisation.Voxelization.AABCGrid grid, Vector3 hitPoint, float hitForce, PhysicalProperties physicalProperties) { this.aabcGrid = grid; this.hitPoint = hitPoint; this.hitForce = hitForce; this.physicalProperties = physicalProperties; findHitVoxel(hitPoint); generateVoronoiPoints(calcRadius(hitForce), calcNumberOfPoints(hitForce)); colourVoxels(); FindIslands(); return(fragmentExtents); }
/// <inheritdoc /> public Part() { _shape = Shape.Cube; _brickColour = new Colour(0.63921570777893f, 0.63529413938522f, 0.64705884456635f); _canCollide = true; _cframe = CFrame.Identity; _modelMatrix = Matrix.Identity; _size = new Vector3(4, 1, 2); _material = Material.Smooth; _smoothness = 0.16f; PhysicalProperties = new PhysicalProperties(0.7f, 0.3f, 0.5f); RebuildRigidBody(); Touched = new Signal <Part>(this); TouchEnded = new Signal <Part>(this); Moved = new Signal(this); }
public Recipe(string name, double energyRequired = 0.5 , RecipeTypes recipeType = RecipeTypes.Normal, PhysicalProperties physicalProperty = PhysicalProperties.Item) { if (energyRequired <= 0) { throw new ArgumentOutOfRangeException(nameof(energyRequired)); } if (!recipeType.Verify()) { throw new ArgumentException($"{nameof(recipeType)} is unexpected types."); } if (!physicalProperty.Verify()) { throw new ArgumentException($"{nameof(physicalProperty)} is unexpected types"); } Name = name ?? throw new ArgumentNullException(nameof(name)); EnergyRequired = energyRequired; RecipeType = recipeType; PhysicalProperty = physicalProperty; }
public void Hit(IBlock block, PhysicalProperties itemProperties) { block.Condition -= 10; }
public override void Hit(IBlockDefinition block, PhysicalProperties itemProperties) { throw new NotImplementedException(); }
public void Read(BinaryReader propReader) { var encode = propReader.ReadInt32(); short declaringTypeId; short propertyTag; DecodePropertyTag(encode, out declaringTypeId, out propertyTag); EncodeTag = encode; DeclaringTypeId = declaringTypeId; PropertyTag = propertyTag; CachedProperty cached; if (TypeRecord.Type.TaggedProperties.TryGetValue(encode, out cached)) { Name = cached.Name; Property = cached; PropertyType = cached.PropertyType; } DataType = (DataType)propReader.ReadByte(); while (propReader.BaseStream.Position < propReader.BaseStream.Length) { switch (DataType) { case DataType.String: Data.Add(propReader.ReadString()); break; case DataType.Content: Data.Add(propReader.ReadString()); break; case DataType.Boolean: Data.Add(propReader.ReadBoolean()); break; case DataType.Int16: Data.Add(propReader.ReadInt16()); break; case DataType.Int32: Data.Add(propReader.ReadInt32()); break; case DataType.Int64: Data.Add(propReader.ReadInt64()); break; case DataType.Single: Data.Add(propReader.ReadSingle()); break; case DataType.Double: Data.Add(propReader.ReadDouble()); break; case DataType.Enum: Data.Add(propReader.ReadInt16()); break; case DataType.FontFamily: Data.Add(new FontFamily(propReader.ReadString())); break; case DataType.Referent: var referent = propReader.ReadInt32(); Data.Add(referent == -1 ? Referent.Null : Context.GlobalReferents[referent]); break; case DataType.UserData: if (VisualC.CompareMemory(propReader.ReadBytes(3), _nullChars, 3) == 0) { Data.Add(null); } else { propReader.BaseStream.Position -= 3; // go back to start var id = propReader.ReadByte(); IDataType userData; switch (id) { case 0: userData = new Vector3(); break; case 1: userData = new Vector2(); break; case 2: userData = new Vector4(); break; case 3: userData = new Colour(); break; case 4: userData = new Axes(); break; case 5: userData = new CFrame(); break; case 6: userData = new UDim2(); break; case 7: userData = new ColourSequence(); break; case 8: userData = new NumberSequence(); break; case 9: userData = new NumberRange(); break; case 10: userData = new Faces(); break; case 11: userData = new Matrix3(); break; case 12: userData = new PhysicalProperties(); break; case 13: userData = new Plane(); break; case 15: userData = new Ray(); break; case 16: userData = new Region3(); break; case 17: userData = new Vector3int16(); break; case 18: userData = new Region3int16(); break; case 19: userData = new DateTime(); break; case 20: userData = new TimeSpan(); break; case 21: userData = new BinaryData(); break; case 22: userData = new MaterialNodeCollection(); break; case 23: userData = new InstanceId(); break; case 24: userData = new FontFamily(); break; default: throw new IndexOutOfRangeException($"No DataType with data ID \"{id}\" found."); } userData.Load(propReader); Data.Add(userData); } break; default: throw new ArgumentOutOfRangeException(); } } }
public void Hit(IItem item, PhysicalProperties itemProperties) { // item.Condition--; }
public void Save(BinaryRobloxFileWriter writer) { BinaryRobloxFile file = writer.File; File = file; INST inst = file.Classes[ClassIndex]; var props = new List <Property>(); foreach (int instId in inst.InstanceIds) { Instance instance = file.Instances[instId]; var instProps = instance.Properties; if (!instProps.TryGetValue(Name, out Property prop)) { throw new Exception($"Property {Name} must be defined in {instance.GetFullName()}!"); } else if (prop.Type != Type) { throw new Exception($"Property {Name} is not using the correct type in {instance.GetFullName()}!"); } props.Add(prop); } writer.Write(ClassIndex); writer.WriteString(Name); writer.Write(TypeId); switch (Type) { case PropertyType.String: props.ForEach(prop => { byte[] buffer = prop.HasRawBuffer ? prop.RawBuffer : null; if (buffer == null) { string value = prop.CastValue <string>(); buffer = Encoding.UTF8.GetBytes(value); } writer.Write(buffer.Length); writer.Write(buffer); }); break; case PropertyType.Bool: { props.ForEach(prop => { bool value = prop.CastValue <bool>(); writer.Write(value); }); break; } case PropertyType.Int: { var ints = props .Select(prop => prop.CastValue <int>()) .ToList(); writer.WriteInts(ints); break; } case PropertyType.Float: { var floats = props .Select(prop => prop.CastValue <float>()) .ToList(); writer.WriteFloats(floats); break; } case PropertyType.Double: { props.ForEach(prop => { double value = prop.CastValue <double>(); writer.Write(BinaryRobloxFileWriter.GetBytes(value)); }); break; } case PropertyType.UDim: { var UDim_Scales = new List <float>(); var UDim_Offsets = new List <int>(); props.ForEach(prop => { UDim value = prop.CastValue <UDim>(); UDim_Scales.Add(value.Scale); UDim_Offsets.Add(value.Offset); }); writer.WriteFloats(UDim_Scales); writer.WriteInts(UDim_Offsets); break; } case PropertyType.UDim2: { var UDim2_Scales_X = new List <float>(); var UDim2_Scales_Y = new List <float>(); var UDim2_Offsets_X = new List <int>(); var UDim2_Offsets_Y = new List <int>(); props.ForEach(prop => { UDim2 value = prop.CastValue <UDim2>(); UDim2_Scales_X.Add(value.X.Scale); UDim2_Scales_Y.Add(value.Y.Scale); UDim2_Offsets_X.Add(value.X.Offset); UDim2_Offsets_Y.Add(value.Y.Offset); }); writer.WriteFloats(UDim2_Scales_X); writer.WriteFloats(UDim2_Scales_Y); writer.WriteInts(UDim2_Offsets_X); writer.WriteInts(UDim2_Offsets_Y); break; } case PropertyType.Ray: { props.ForEach(prop => { Ray ray = prop.CastValue <Ray>(); Vector3 pos = ray.Origin; writer.Write(pos.X); writer.Write(pos.Y); writer.Write(pos.Z); Vector3 dir = ray.Direction; writer.Write(dir.X); writer.Write(dir.Y); writer.Write(dir.Z); }); break; } case PropertyType.Faces: case PropertyType.Axes: { props.ForEach(prop => { byte value = prop.CastValue <byte>(); writer.Write(value); }); break; } case PropertyType.BrickColor: { var brickColorIds = props .Select(prop => prop.CastValue <BrickColor>()) .Select(value => value.Number) .ToList(); writer.WriteInts(brickColorIds); break; } case PropertyType.Color3: { var Color3_R = new List <float>(); var Color3_G = new List <float>(); var Color3_B = new List <float>(); props.ForEach(prop => { Color3 value = prop.CastValue <Color3>(); Color3_R.Add(value.R); Color3_G.Add(value.G); Color3_B.Add(value.B); }); writer.WriteFloats(Color3_R); writer.WriteFloats(Color3_G); writer.WriteFloats(Color3_B); break; } case PropertyType.Vector2: { var Vector2_X = new List <float>(); var Vector2_Y = new List <float>(); props.ForEach(prop => { Vector2 value = prop.CastValue <Vector2>(); Vector2_X.Add(value.X); Vector2_Y.Add(value.Y); }); writer.WriteFloats(Vector2_X); writer.WriteFloats(Vector2_Y); break; } case PropertyType.Vector3: { var Vector3_X = new List <float>(); var Vector3_Y = new List <float>(); var Vector3_Z = new List <float>(); props.ForEach(prop => { Vector3 value = prop.CastValue <Vector3>(); Vector3_X.Add(value.X); Vector3_Y.Add(value.Y); Vector3_Z.Add(value.Z); }); writer.WriteFloats(Vector3_X); writer.WriteFloats(Vector3_Y); writer.WriteFloats(Vector3_Z); break; } case PropertyType.CFrame: case PropertyType.Quaternion: case PropertyType.OptionalCFrame: { var CFrame_X = new List <float>(); var CFrame_Y = new List <float>(); var CFrame_Z = new List <float>(); if (Type == PropertyType.OptionalCFrame) { writer.Write((byte)PropertyType.CFrame); } props.ForEach(prop => { CFrame value = null; if (prop.Value is Quaternion q) { value = q.ToCFrame(); } else { value = prop.CastValue <CFrame>(); } if (value == null) { value = new CFrame(); } Vector3 pos = value.Position; CFrame_X.Add(pos.X); CFrame_Y.Add(pos.Y); CFrame_Z.Add(pos.Z); int orientId = value.GetOrientId(); writer.Write((byte)(orientId + 1)); if (orientId == -1) { if (Type == PropertyType.Quaternion) { Quaternion quat = new Quaternion(value); writer.Write(quat.X); writer.Write(quat.Y); writer.Write(quat.Z); writer.Write(quat.W); } else { float[] components = value.GetComponents(); for (int i = 3; i < 12; i++) { float component = components[i]; writer.Write(component); } } } }); writer.WriteFloats(CFrame_X); writer.WriteFloats(CFrame_Y); writer.WriteFloats(CFrame_Z); if (Type == PropertyType.OptionalCFrame) { writer.Write((byte)PropertyType.Bool); props.ForEach(prop => { if (prop.Value is null) { writer.Write(false); return; } if (prop.Value is Optional <CFrame> optional) { writer.Write(optional.HasValue); return; } var cf = prop.Value as CFrame; writer.Write(cf != null); }); } break; } case PropertyType.Enum: { var enums = new List <uint>(); props.ForEach(prop => { if (prop.Value is uint raw) { enums.Add(raw); return; } int signed = (int)prop.Value; uint value = (uint)signed; enums.Add(value); }); writer.WriteInterleaved(enums); break; } case PropertyType.Ref: { var InstanceIds = new List <int>(); props.ForEach(prop => { int referent = -1; if (prop.Value != null) { Instance value = prop.CastValue <Instance>(); if (value.IsDescendantOf(File)) { string refValue = value.Referent; int.TryParse(refValue, out referent); } } InstanceIds.Add(referent); }); writer.WriteInstanceIds(InstanceIds); break; } case PropertyType.Vector3int16: { props.ForEach(prop => { Vector3int16 value = prop.CastValue <Vector3int16>(); writer.Write(value.X); writer.Write(value.Y); writer.Write(value.Z); }); break; } case PropertyType.NumberSequence: { props.ForEach(prop => { NumberSequence value = prop.CastValue <NumberSequence>(); var keyPoints = value.Keypoints; writer.Write(keyPoints.Length); foreach (var keyPoint in keyPoints) { writer.Write(keyPoint.Time); writer.Write(keyPoint.Value); writer.Write(keyPoint.Envelope); } }); break; } case PropertyType.ColorSequence: { props.ForEach(prop => { ColorSequence value = prop.CastValue <ColorSequence>(); var keyPoints = value.Keypoints; writer.Write(keyPoints.Length); foreach (var keyPoint in keyPoints) { Color3 color = keyPoint.Value; writer.Write(keyPoint.Time); writer.Write(color.R); writer.Write(color.G); writer.Write(color.B); writer.Write(keyPoint.Envelope); } }); break; } case PropertyType.NumberRange: { props.ForEach(prop => { NumberRange value = prop.CastValue <NumberRange>(); writer.Write(value.Min); writer.Write(value.Max); }); break; } case PropertyType.Rect: { var Rect_X0 = new List <float>(); var Rect_Y0 = new List <float>(); var Rect_X1 = new List <float>(); var Rect_Y1 = new List <float>(); props.ForEach(prop => { Rect value = prop.CastValue <Rect>(); Vector2 min = value.Min; Rect_X0.Add(min.X); Rect_Y0.Add(min.Y); Vector2 max = value.Max; Rect_X1.Add(max.X); Rect_Y1.Add(max.Y); }); writer.WriteFloats(Rect_X0); writer.WriteFloats(Rect_Y0); writer.WriteFloats(Rect_X1); writer.WriteFloats(Rect_Y1); break; } case PropertyType.PhysicalProperties: { props.ForEach(prop => { bool custom = (prop.Value != null); writer.Write(custom); if (custom) { PhysicalProperties value = prop.CastValue <PhysicalProperties>(); writer.Write(value.Density); writer.Write(value.Friction); writer.Write(value.Elasticity); writer.Write(value.FrictionWeight); writer.Write(value.ElasticityWeight); } }); break; } case PropertyType.Color3uint8: { var Color3uint8_R = new List <byte>(); var Color3uint8_G = new List <byte>(); var Color3uint8_B = new List <byte>(); props.ForEach(prop => { Color3uint8 value = prop.CastValue <Color3uint8>(); Color3uint8_R.Add(value.R); Color3uint8_G.Add(value.G); Color3uint8_B.Add(value.B); }); byte[] rBuffer = Color3uint8_R.ToArray(); writer.Write(rBuffer); byte[] gBuffer = Color3uint8_G.ToArray(); writer.Write(gBuffer); byte[] bBuffer = Color3uint8_B.ToArray(); writer.Write(bBuffer); break; } case PropertyType.Int64: { var longs = new List <long>(); props.ForEach(prop => { long value = prop.CastValue <long>(); longs.Add(value); }); writer.WriteInterleaved(longs, value => { // Move the sign bit to the front. return((value << 1) ^ (value >> 63)); }); break; } case PropertyType.SharedString: { var sharedKeys = new List <uint>(); SSTR sstr = file.SSTR; if (sstr == null) { sstr = new SSTR(); file.SSTR = sstr; } props.ForEach(prop => { var shared = prop.CastValue <SharedString>(); if (shared == null) { byte[] empty = Array.Empty <byte>(); shared = SharedString.FromBuffer(empty); } string key = shared.Key; if (!sstr.Lookup.ContainsKey(key)) { uint id = (uint)sstr.Lookup.Count; sstr.Strings.Add(id, shared); sstr.Lookup.Add(key, id); } uint hashId = sstr.Lookup[key]; sharedKeys.Add(hashId); }); writer.WriteInterleaved(sharedKeys); break; } case PropertyType.ProtectedString: { props.ForEach(prop => { var protect = prop.CastValue <ProtectedString>(); byte[] buffer = protect.RawBuffer; writer.Write(buffer.Length); writer.Write(buffer); }); break; } case PropertyType.UniqueId: { props.ForEach(prop => { var guid = prop.CastValue <Guid>(); byte[] buffer = guid.ToByteArray(); writer.Write(buffer); }); break; } default: { RobloxFile.LogError($"Unhandled property type: {Type} in {this}!"); break; } } }
public void Hit(IBlock block, PhysicalProperties itemProperties) { throw new NotImplementedException(); }
public void SplitDestroy(Vector3 hitPoint, float hitForce, PhysicalProperties physicalProperties) { messages.Add("Starting"); float time = Time.realtimeSinceStartup; float startTime = time; voxelisationDriver.StartVoxelise(gameObject); messages.Add("Voxelisation: " + (Time.realtimeSinceStartup - time)); csvList.Add((Time.realtimeSinceStartup - time) + " "); time = Time.realtimeSinceStartup; grid = voxelisationDriver.GetGrid(); fragments = destruction.Fragment(grid, hitPoint, hitForce, physicalProperties); messages.Add("Destruction: " + (Time.realtimeSinceStartup - time)); csvList.Add((Time.realtimeSinceStartup - time) + " "); time = Time.realtimeSinceStartup; colouring = destruction.getVoronoiDiagram(); foreach (Fragment c in fragments.Values) { c.vertices.Clear(); } short[, ,] borderColouring = new short[colouring.GetLength(0), colouring.GetLength(1), colouring.GetLength(2)]; List <Vector3> vectors = new List <Vector3>(); for (int i = 0; i < colouring.GetLength(0); i++) { for (int j = 0; j < colouring.GetLength(1); j++) { for (int k = 0; k < colouring.GetLength(2); k++) { short c = colouring[i, j, k]; bool neighbours = false; bool exterior = false; if (c == 0) { continue; } for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { if (i + x < 0 || j + y < 0 || k + z < 0) { continue; } if (i + x >= colouring.GetLength(0) || j + y >= colouring.GetLength(1) || k + z >= colouring.GetLength(2)) { continue; } if (colouring[i + x, j + y, k + z] != c && colouring[i + x, j + y, k + z] != 0) { neighbours = true; } if (colouring[i + x, j + y, k + z] == 0) { exterior = true; } } } } if (exterior) { vectors.Add(new Vector3(i, j, k)); } if (neighbours) { borderColouring[i, j, k] = c; } if (neighbours && exterior) { Fragment colour; if (fragments.TryGetValue(c, out colour)) { colour.vertices.Add(new Vector3(i, j, k)); } } } } } KDTree tree = KDTree.MakeFromPoints(vectors.ToArray()); messages.Add("KDTree: " + (Time.realtimeSinceStartup - time)); time = Time.realtimeSinceStartup; MeshInfo original = new MeshInfo(gameObject.GetComponent <MeshFilter>().mesh.vertices, gameObject.GetComponent <MeshFilter>().mesh.triangles, new Fragment(0)); Dictionary <short, MeshInfo> meshes = splitMesh.Split(original, tree, vectors, colouring, grid.GetSize()); messages.Add("Split: " + (Time.realtimeSinceStartup - time)); csvList.Add((Time.realtimeSinceStartup - time) + " "); time = Time.realtimeSinceStartup; if (!hollow) { csvList.Add("Meshing "); foreach (Fragment colour in fragments.Values) { if (colour == null) { continue; } MeshInfo meshinfo, march; MeshInfo parent; bool found = meshes.TryGetValue(colour.colour, out parent); colors.Add(colour.colour, new Color(Random.value, Random.value, Random.value)); if (found) { List <Vector3> edges = parent.colour.vertices; List <Vector3> exterior = new List <Vector3>(); foreach (Vector3 v in colour.vertices) { exterior.Add(toWorldSpace(v)); } Vector3 voxelMid = new Vector3((colour.maxX - colour.minX) / 2, (colour.maxY - colour.minY) / 2, (colour.maxZ - colour.minZ) / 2); voxelMid.x = voxelMid.x / grid.GetSize().x; voxelMid.y = voxelMid.y / grid.GetSize().y; voxelMid.z = voxelMid.z / grid.GetSize().z; voxelMid *= 2; KDTree surface = KDTree.MakeFromPoints(edges.ToArray()); //meshinfo = holefill.Stitch(edges, colour, exterior); meshinfo = marchingDriver.StartMarchingClamp(borderColouring, colour, grid, surface, edges); } else { meshinfo = marchingDriver.StartMarching(borderColouring, colour, grid); march = marchingDriver.StartMarching(borderColouring, colour, grid); } //meshinfo = convexDriver.StartMeshing(colour); /*for (int c = 0; c < meshinfo.verts.Length; c++) { * meshinfo.verts[c] = new Vector3(meshinfo.verts[c].x / transform.lossyScale.x, meshinfo.verts[c].y / transform.lossyScale.y, meshinfo.verts[c].z / transform.lossyScale.z); * }*/ messages.Add("Meshing " + colour.colour + ": " + (Time.realtimeSinceStartup - time)); csvList.Add((Time.realtimeSinceStartup - time) + " "); time = Time.realtimeSinceStartup; if (colour.colour == 0) { continue; } else { if (found) { List <Vector3> verts = new List <Vector3>(parent.verts); int count = verts.Count; verts.AddRange(meshinfo.verts); List <int> indices = new List <int>(parent.index); foreach (int i in meshinfo.index) { indices.Add(i + count); } /*count = verts.Count; * verts.AddRange(march.verts); * * foreach (int i in march.index) { * indices.Add(i + count); * }*/ parent.verts = verts.ToArray(); parent.index = indices.ToArray(); parent.colour.mass = meshinfo.colour.mass; } else { meshes.Add(colour.colour, meshinfo); } } } } csvList.Add("Building "); foreach (MeshInfo meshinfo in meshes.Values) { Mesh mesh = new Mesh(); Fragment coloured = meshinfo.colour; fragments.TryGetValue(coloured.colour, out coloured); if (coloured.colour == 0) { continue; } mesh.vertices = meshinfo.verts; mesh.triangles = meshinfo.index; //The diffuse shader wants uvs so just fill with a empty array, they're not actually used mesh.uv = new Vector2[mesh.vertices.Length]; mesh.RecalculateNormals(); mesh.RecalculateBounds(); Mesh mesh1 = new Mesh(); if (hollow) { List <int> indices = new List <int>(meshinfo.index); for (int i = 0; i < meshinfo.index.Length; i += 3) { indices.Add(meshinfo.index[i + 2]); indices.Add(meshinfo.index[i + 1]); indices.Add(meshinfo.index[i + 0]); } meshinfo.index = indices.ToArray(); /*List<Vector3> normals = new List<Vector3>(mesh.normals); * for (int i = 0; i < mesh.normals.Length; i++) * normals.Add(-normals[i]);*/ mesh1.vertices = meshinfo.verts; mesh1.triangles = meshinfo.index; //The diffuse shader wants uvs so just fill with a empty array, they're not actually used mesh1.uv = new Vector2[mesh.vertices.Length]; mesh1.normals = mesh.normals; } GameObject m_mesh = new GameObject("Fragment" + coloured.colour); m_mesh.AddComponent <MeshFilter>(); m_mesh.AddComponent <MeshRenderer>(); //MeshCollider col1 = m_mesh.AddComponent<MeshCollider>(); MeshCollider col2 = m_mesh.AddComponent <MeshCollider>(); m_mesh.AddComponent <Rigidbody>(); //m_mesh.rigidbody.isKinematic = true; m_mesh.rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; m_mesh.rigidbody.mass = coloured.mass; m_mesh.renderer.material = m_material; //col1.sharedMesh = mesh; col2.sharedMesh = mesh; col2.convex = true; m_mesh.GetComponent <MeshFilter>().mesh = hollow ? mesh1 : mesh; m_mesh.transform.localScale = transform.localScale; messages.Add("Built " + coloured.colour + ": " + (Time.realtimeSinceStartup - time)); csvList.Add((Time.realtimeSinceStartup - time) + " "); time = Time.realtimeSinceStartup; } messages.Add("Done:" + (Time.realtimeSinceStartup - startTime)); string csv = ""; foreach (string str in csvList) { csv += str; } foreach (string str in messages) { Debug.Log(str); } //Debug.Log(csv); done = true; GameObject.Destroy(gameObject); if (breakP) { Debug.Break(); } }
protected BasePart() { CustomPhysicalProperties = new PhysicalProperties(false); }
/// <summary> /// Adds the mesh for the given component, and all its subcomponents to the mesh storage structure. /// </summary> /// <param name="occ">Component occurence to analize.</param> /// <param name="mesh">Mesh to store physics data in.</param> /// <param name="ignorePhysics">True to ignore physics in component.</param> /// <returns>All the sufaces to export</returns> private void GenerateExportList(ComponentOccurrence occ, List <SurfaceBody> plannedExports, PhysicalProperties physics, double minVolume = 0, bool ignorePhysics = false) { // Invisible objects don't need to be exported if (!occ.Visible) { return; } if (!ignorePhysics) { // Compute physics try { physics.Add((float)occ.MassProperties.Mass, Utilities.ToBXDVector(occ.MassProperties.CenterOfMass)); } catch { Console.Write("Failed to get physics data for " + occ.Name); } } // Prepare exporting surfaces foreach (SurfaceBody surf in occ.SurfaceBodies) { plannedExports.Add(surf); } // Add sub-occurences foreach (ComponentOccurrence subOcc in occ.SubOccurrences) { if (Utilities.BoxVolume(subOcc.RangeBox) >= minVolume) { GenerateExportList(subOcc, plannedExports, physics, minVolume, true); } } }