public void Init(ICoreAPI api, ClothManager cm) { this.api = api; this.capi = api as ICoreClientAPI; pp = cm.partPhysics; noiseGen = NormalizedSimplexNoise.FromDefaultOctaves(4, 100, 0.9, api.World.Seed + CenterPosition.GetHashCode()); if (capi != null && LineDebug) { debugUpdateMesh = new MeshData(20, 15, false, false, true, true); } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); cm = api.ModLoader.GetModSystem <ClothManager>(); }
public static ClothSystem CreateRope(ICoreAPI api, ClothManager cm, BlockPos originPos, float length, AssetLocation clothSectionModel) { return(new ClothSystem(api, cm, originPos, length, 0, EnumClothType.Rope, clothSectionModel)); }
private ClothSystem(ICoreAPI api, ClothManager cm, BlockPos originPos, float xsize, float zsize, EnumClothType clothType, AssetLocation ropeSectionModel = null) { this.clothType = clothType; this.ropeSectionModel = ropeSectionModel; Init(api, cm); Random rand = api.World.Rand; bool hor = rand.NextDouble() < 0.5; int vertexIndex = 0; float step = 1 / Resolution; int numzpoints = (int)Math.Round(zsize * Resolution); int numxpoints = (int)Math.Round(xsize * Resolution); if (clothType == EnumClothType.Rope) { numzpoints = 1; } float roughness = 0.05f; int k = 0; int pointIndex = 0; for (int z = 0; z < numzpoints; z++) { Points2d.Add(new PointList()); for (int x = 0; x < numxpoints; x++) { float dx = x * step; float dy = z * step; float dz = -roughness / 2 + (float)rand.NextDouble() * roughness; if (hor) { dx = x * step; dy = -roughness / 2 + (float)rand.NextDouble() * roughness; dz = z * step; } var point = new ClothPoint(this, pointIndex++, originPos.X + dx, originPos.Y + dy, originPos.Z + dz); Points2d[z].Points.Add(point); int color = (k++ % 2) > 0 ? ColorUtil.WhiteArgb : ColorUtil.BlackArgb; // add a vertical constraint if (z > 0) { ClothPoint p1 = Points2d[z - 1].Points[x]; ClothPoint p2 = Points2d[z].Points[x]; var constraint = new ClothConstraint(p1, p2); Constraints.Add(constraint); if (capi != null) { if (LineDebug) { debugUpdateMesh.AddVertex(0, 0, 0, color); debugUpdateMesh.AddVertex(0, 0, 0, color); debugUpdateMesh.AddIndex(vertexIndex++); debugUpdateMesh.AddIndex(vertexIndex++); } } } // add a new horizontal constraints if (x > 0) { ClothPoint p1 = Points2d[z].Points[x - 1]; ClothPoint p2 = Points2d[z].Points[x]; var constraint = new ClothConstraint(p1, p2); Constraints.Add(constraint); if (capi != null) { if (LineDebug) { debugUpdateMesh.AddVertex(0, 0, 0, color); debugUpdateMesh.AddVertex(0, 0, 0, color); debugUpdateMesh.AddIndex(vertexIndex++); debugUpdateMesh.AddIndex(vertexIndex++); } } } } } if (capi != null && LineDebug) { debugUpdateMesh.mode = EnumDrawMode.Lines; debugMeshRef = capi.Render.UploadMesh(debugUpdateMesh); debugUpdateMesh.Indices = null; debugUpdateMesh.Rgba = null; } }
public static ClothSystem CreateCloth(ICoreAPI api, ClothManager cm, BlockPos originPos, float xsize, float zsize) { return(new ClothSystem(api, cm, originPos, xsize, zsize, EnumClothType.Cloth)); }