private static void ConvertSETItem(List <COL> newcollist, SETItem item, bool solid, int ind) { NJS_OBJECT obj = new NJS_OBJECT() { Scale = new Vertex(1, 1, 1), Name = item.InternalName + " " + ind }; BasicAttach attach = new BasicAttach(); obj.Attach = attach; foreach (ModelTransform mt in item.GetObjectDefinition().GetModels(item, new MatrixStack())) { MatrixStack transform = new MatrixStack(); transform.LoadMatrix(mt.Transform); ProcessModel(mt.Model.Clone(), transform, attach); } attach.ProcessVertexData(); attach.CalculateBounds(); COL col = new COL() { Model = obj, SurfaceFlags = SurfaceFlags.Visible }; if (solid) { col.SurfaceFlags |= SurfaceFlags.Solid | SurfaceFlags.Unclimbable; } col.CalculateBounds(); ConvertCOL(newcollist, new Dictionary <string, Attach>(), col); }
public static void Draw_ArcGraph(Graph _graph, float _x, float _y, float _radius_START, float _radius_END, float _angle_MIN, float _angle_MAX, Color _col_MIN, Color _col_MAX, bool _alphaFade = false, int _sides = DEFAULT_ARC_SIDES, float _gutterRatio = DEFAULT_GUTTER_RATIO) { int _COUNT = _graph.binCount; float _DRAW_RANGE = _radius_END - _radius_START; float _BAR_SPACE = _DRAW_RANGE * _gutterRatio; float _BAR_THICKNESS = _BAR_SPACE / _COUNT; float _GUTTER = (_DRAW_RANGE - _BAR_SPACE) / (_COUNT - 1f); float _ANGLE_RANGE = _angle_MAX - _angle_MIN; for (int i = 0; i < _COUNT; i++) { float _BAR_START = _radius_START + ((i * _BAR_THICKNESS) + (i * _GUTTER)); float _BIN_VALUE = _graph.Get_Value(i); Color _COL = Color.Lerp(_col_MIN, _col_MAX, _BIN_VALUE); GL_DRAW.Draw_ARC_FILL( _sides, _x, _y, _angle_MIN, (_angle_MIN + (_ANGLE_RANGE * _BIN_VALUE)), _BAR_START, _BAR_START + _BAR_THICKNESS, (_alphaFade) ? COL.Set_alphaStrength(_COL, _BIN_VALUE) : _COL ); } }
public IList <HoursClause> GetHoursClauses() { if (HoursClauses != null) { return(HoursClauses); } if (!Declarations.ContainsKey("Hours Clauses") || (Declarations["Hours Clauses"] as object[]).Length == 0) { return(EMPTYLIST_HOURSCLAUSE); } HoursClauses = new List <HoursClause>((Declarations["Hours Clauses"] as object[]).Length); foreach (object _HoursClauseKVP in (Declarations["Hours Clauses"] as object[])) { Dictionary <string, object> HoursClauseKVP = _HoursClauseKVP as Dictionary <string, object>; HashSet <SymbolicValue> CausesOfLoss = null; if (HoursClauseKVP.ContainsKey("CausesOfLoss")) { CausesOfLoss = new HashSet <SymbolicValue>(); foreach (string COL in ((string)HoursClauseKVP["CausesOfLoss"]).Split(',')) { CausesOfLoss.Add(new SymbolicValue(COL.Trim())); } } HoursClauses.Add(new HoursClause(int.Parse(HoursClauseKVP["Duration"].ToString()), (HoursClause.Unit)Enum.Parse(typeof(HoursClause.Unit), (string)HoursClauseKVP["DurationTimeUnit"]), bool.Parse((string)HoursClauseKVP["OnlyOnce"]), CausesOfLoss)); } return(HoursClauses); }
public override int GetHashCode() { if (UniversalSubject == null) { throw new NotSupportedException("UniversalSubject not yet initialized!"); } int hash = 23; hash = hash * 37 + PerRisk.GetHashCode(); if ((Components == null) || (Components.Count == 0)) { hash = hash * 37 + 41; } else { foreach (SymbolicValue COL in Components.Keys) { hash = hash * 37 + COL.GetHashCode(); foreach (int ResolvedExposureType in Components[COL].Keys) { hash = hash * 37 + ResolvedExposureType.GetHashCode(); HashSet <long> Components_COL_ResolvedExposureType = Components[COL][ResolvedExposureType].Item1; foreach (long RITEId in Components_COL_ResolvedExposureType) { hash = hash * 37 + RITEId.GetHashCode(); } } } } return(hash); }
static IEnumerator FadeNow(FadeParams p) { Image go = p.image; Text t = p.txt; COL c0 = p.c0, c1 = p.c1; float duration = p.duration; //start colours. 0 to 1.0 float r = c0.r / 255.0f, g = c0.g / 255.0f, b = c0.b / 255.0f, a = c0.a / 255.0f; float dr, dg, db, da; //deltas:0 to 1.0 dr = (c1.r - c0.r) / 255.0f; dg = (c1.g - c0.g) / 255.0f; db = (c1.b - c0.b) / 255.0f; da = (c1.a - c0.a) / 255.0f; Color col = new Color(); //print ("col-start"); float timestart = Time.time; float timeend = timestart + duration; float timecur, percent; while (true) { timecur = Time.time; if (timecur > timeend) { break; } percent = (timecur - timestart) / duration; col.r = Mathf.Clamp(r + percent * dr, 0.0f, 1.0f); col.g = Mathf.Clamp(g + percent * dg, 0.0f, 1.0f); col.b = Mathf.Clamp(b + percent * db, 0.0f, 1.0f); col.a = Mathf.Clamp(a + percent * da, 0.0f, 1.0f); if (go != null) { go.color = col; } else { t.color = col; } yield return(new WaitForSeconds(0.01f)); } //final fix bcos time might have elapsed and fade didnt complete if (go != null) { go.color = c1.toColor(); } if (t != null) { t.color = c1.toColor(); } //print ("col-end" + (Time.time - timestart)); }
/// <summary> /// Creates a LevelItem from an existing COL data. /// </summary> /// <param name="col"></param> /// <param name="dev">Current Direct3d Device.</param> public LevelItem(COL col, Device dev, int index, EditorItemSelection selectionManager) : base(selectionManager) { this.index = index; COL = col; col.Model.ProcessVertexData(); Mesh = col.Model.Attach.CreateD3DMesh(dev); }
private string ProcessCOL(COL col) { if (col.Name == "*") { return(col.Name); } return(string.Format("[{0}]", col.Name)); }
public SCREEN_4_GRAPHS() { duration = 10f; title = "graphing"; P = COL.Get_Palette(0); _arcGraph1 = new Graph(5); _arcGraph2 = new Graph(20); }
public static void INIT(Color[] _palette, Material _mat) { // init material mat = _mat; GL_FONT_3x5.Init(); GL_MATRIX_ANIMS.Init(); COL.INIT_PALETTES(_palette); }
public override int GetHashCode() { int code = 0; foreach (CauseOfLoss COL in collection) { code = code + 31 * COL.GetHashCode(); } return(code); }
public static void Fade(Text t, COL c0, COL c1, int duration) { FadeParams p; p.image = null; p.txt = t; p.c0 = c0; p.c1 = c1; p.duration = ((float)duration) / 1000.0f; MonoObj.pmono.StartCoroutine(Lib.FadeNow(p)); }
public SCREEN_EXAMPLE2() { duration = 30f; title = "hud example 2"; P = COL.Get_Palette(0); sprawls = new DataSprawl[sprawlCount]; for (int i = 0; i < sprawlCount; i++) { sprawls[i] = new DataSprawl(10, 10, 4, 10); } }
void WallCell(float _x, float _y, float _w, float _h, Color _col, int _sprawlIndex, float _animOffset, float _tickerOffset) { bool _TICKER = Anim.Runtime_int(5f, _tickerOffset) % 2 == 0; float _TOP = _y + _h; float _lw = _w * 0.5f; GL_DRAW.Draw_RECT(_x - (_w * 0.1f), _y + (_h * 0.1f), _lw, _h, COL.Set_alphaStrength(_col, 0.2f)); GL_DRAW.Draw_RECT(_x - (_w * 0.05f), _y + (_h * 0.05f), _lw, _h, COL.Set_alphaStrength(_col, 0.2f)); GL_DRAW.Draw_RECT_FILL(_x, _y, _lw, _h, COL.Set_alphaStrength(_col, 0.2f)); GL_DRAW.Draw_RECT_FILL(_x, _TOP, _lw, _h * -0.1f, COL.Set_alphaStrength(_col, _TICKER ? 0.05f : 0.3f)); HUD.Draw_LABEL_BOX("a" + _sprawlIndex, _x + (_lw * 0.1f), _y + (_h * 0.1f), _lw * 0.6f, _h * 0.6f, 0.01f, 0.1f, 0.5f, _col, P.Get(0)); GL_MATRIX_ANIMS.Draw(GL_MATRIX_ANIMS.NAME_INC_3X3, Anim.Runtime_int(3f, _animOffset + Anim.Sin_Time(1.1f, 0f, 3f)), _x + _lw, _y + (_h * 0.75f), _h * 0.25f, _col); sprawls[_sprawlIndex].Draw(_x + _lw, _y + (_h * 0.75f), _lw * 0.25f, _h * -0.75f, COL.Set_alphaStrength(_col, 0.25f)); }
static bool CompareCOL(COL item1, COL item2, int tryhard = 0) { if (item1.Bounds.Center.X != item2.Bounds.Center.X) { return(false); } if (item1.Bounds.Center.Y != item2.Bounds.Center.Y) { return(false); } if (item1.Bounds.Center.Z != item2.Bounds.Center.Z) { return(false); } if (item1.Bounds.Radius != item2.Bounds.Radius) { if (tryhard < 1) { return(false); } else { Console.WriteLine("Radius different for COL item at {0} / {1} / {2}: {3} vs {4}", item1.Bounds.Center.X, item1.Bounds.Center.Y, item1.Bounds.Center.Z, item1.Bounds.Radius, item2.Bounds.Radius); } } if (item1.Flags != item2.Flags) { if (tryhard < 1) { return(false); } else { Console.WriteLine("Flags different for COL item at {0} / {1} / {2}: {3} vs {4}", item1.Bounds.Center.X, item1.Bounds.Center.Y, item1.Bounds.Center.Z, item1.Flags.ToString("X"), item2.Flags.ToString("X")); } } if (item1.SurfaceFlags != item2.SurfaceFlags) { if (tryhard < 1) { return(false); } else { Console.WriteLine("Surface flags different for COL item at {0} / {1} / {2}: {3} vs {4}", item1.Bounds.Center.X, item1.Bounds.Center.Y, item1.Bounds.Center.Z, item1.SurfaceFlags.ToString("X"), item2.SurfaceFlags.ToString("X")); } } return(true); }
/// <summary> /// /// </summary> /// <param name="argCompond"></param> /// <param name="argTheoreticalMonoIdx"></param> /// <param name="argIntensities"></param> /// <returns></returns> public static double IntensityNormalizationFactorByIsotope(COL.GlycoLib.GlycanCompound argCompond, int argNumOfLabelingSite, double[] argIntensities, float argPurity) { ChemicalFormula MonoChemFormula = new ChemicalFormula(); MonoChemFormula.Add("C", argCompond.Carbon+argCompond.Carbon13); MonoChemFormula.Add("H", argCompond.Hydrogen+argCompond.Deuterium); MonoChemFormula.Add("O", argCompond.Oxygen); //if (argCompond.Carbon13 != 0) //{ // MonoChemFormula.Add("C{13}", argCompond.Carbon13); //} //if (argCompond.Deuterium != 0) //{ // MonoChemFormula.Add("D", argCompond.Deuterium); //} if (argCompond.Sodium != 0) { MonoChemFormula.Add("Na", argCompond.Sodium); } if (argCompond.Nitrogen != 0) { MonoChemFormula.Add("N", argCompond.Nitrogen); } IsotopicDistribution ID = new IsotopicDistribution(); MZPeak[] Peaks= ID.CalculateDistribuition(MonoChemFormula,7, IsotopicDistribution.Normalization.BasePeak).GetPeaks().ToArray(); double[] isotopeRatio = new double[7]; for (int i = 0; i < 7; i++) { isotopeRatio[i] = Peaks[i].Intensity; } double[] CorrectedIntensities = (double[] )argIntensities.Clone(); //Isotope Correction for (int i = 0; i <= 2; i++) { double Ratio = CorrectedIntensities[i]/ isotopeRatio[0]; for (int j = i; j < 7; j++) { CorrectedIntensities[j] = CorrectedIntensities[j] - (isotopeRatio[j-i] * Ratio ); } } double isotopeCorrectionFactor = CorrectedIntensities[3] / argIntensities[3]; // Purity Correction //double PurityCorrection = Math.Pow(argPurity, argNumOfLabelingSite); return isotopeCorrectionFactor; }
/// <summary> /// Creates a Levelitem from an external file. /// </summary> /// <param name="dev">Current Direct3D device.</param> /// <param name="filePath">location of the file to use.</param> /// <param name="position">Position to place the resulting model (worldspace).</param> /// <param name="rotation">Rotation to apply to the model.</param> public LevelItem(Device dev, string filePath, Vertex position, Rotation rotation, int index, EditorItemSelection selectionManager) : base(selectionManager) { this.index = index; COL = new COL { Model = new NJS_OBJECT { Position = position, Rotation = rotation } }; ImportModel(filePath, dev); COL.CalculateBounds(); Paste(); }
public override bool Equals(object obj) { var TBL = obj as Table; if (TBL == null) { return(!(add = true)); } foreach (Column COL in Columns.Values) { if (!COL.Equals(TBL.Columns[COL.Name])) { mod = true; } } return(Name == TBL.Name && Columns.Count == TBL.Columns.Count && !mod); }
/// <summary> /// Creates a Levelitem from an external file. /// </summary> /// <param name="dev">Current Direct3D device.</param> /// <param name="filePath">location of the file to use.</param> /// <param name="position">Position to place the resulting model (worldspace).</param> /// <param name="rotation">Rotation to apply to the model.</param> public LevelItem(string filePath, Vertex position, Rotation rotation, int index, EditorItemSelection selectionManager, bool legacyImport = false) : base(selectionManager) { this.index = index; COL = new COL { Model = new NJS_OBJECT { Position = position, Rotation = rotation } }; ImportModel(filePath, legacyImport); COL.CalculateBounds(); Paste(); GetHandleMatrix(); }
public void init(int _tile_id, COLOR _color, ROW _row, COL _col) { color = _color; row = _row; col = _col; tile_id = _tile_id; //GENERATE WAYPOINTS ID wp_tl = new waypoint(tile_id * 5 + 0, this); wp_tr = new waypoint(tile_id * 5 + 1, this); wp_bl = new waypoint(tile_id * 5 + 2, this); wp_br = new waypoint(tile_id * 5 + 3, this); wp_center = new waypoint(tile_id * 5 + 3, this); //CALC POSTIONS FOR EACH WP wp_center.pos_x = this.gameObject.transform.position.x; wp_center.pos_y = this.gameObject.transform.position.z; }
public override int GetHashCode() { if (UniversalSubject == null) { throw new NotSupportedException("UniversalSubject not yet initialized!"); } int hash = 23; hash = hash * 37 + PerRisk.GetHashCode(); //if ((Components == null) || (Components.Count == 0)) // hash = hash * 37 + 41; //else // foreach (Tuple<int, long, SymbolicValue> Component in Components) // { // hash = hash * 37 + Component.Item1.GetHashCode(); // hash = hash * 37 + Component.Item2.GetHashCode(); // hash = hash * 37 + Component.Item3.GetHashCode(); // } if ((Components == null) || (Components.Count == 0)) { hash = hash * 37 + 41; } else { foreach (SymbolicValue COL in Components.Keys) { hash = hash * 37 + COL.GetHashCode(); foreach (int ResolvedExposureType in Components[COL].Keys) { hash = hash * 37 + ResolvedExposureType.GetHashCode(); foreach (long RITEId in Components[COL][ResolvedExposureType]) { hash = hash * 37 + RITEId.GetHashCode(); } } } } return(hash); }
public static void Draw_BarGraph_Y(Graph _graph, float _x, float _y, float _w, float _h, Color _col_MIN, Color _col_MAX, bool _alphaFade = false, float _gutterRatio = DEFAULT_GUTTER_RATIO) { int _COUNT = _graph.binCount; float _BAR_SPACE = _h * _gutterRatio; float _BAR_THICKNESS = _BAR_SPACE / _COUNT; float _GUTTER = (_h - _BAR_SPACE) / (_COUNT - 1); for (int i = 0; i < _COUNT; i++) { float _BIN_VALUE = _graph.Get_Value(i); Color _COL = Color.Lerp(_col_MIN, _col_MAX, _BIN_VALUE); GL_DRAW.Draw_RECT_FILL( _x, _y + ((_BAR_THICKNESS * i) + (_GUTTER * i)), _w * _BIN_VALUE, _BAR_THICKNESS, (_alphaFade) ? COL.Set_alphaStrength(_COL, _BIN_VALUE) : _COL); } }
/// <summary> /// Creates a new instance of an existing item with the specified position and rotation. /// </summary> /// <param name="attach">Attach to use for this levelItem</param> /// <param name="position">Position in worldspace to place this LevelItem.</param> /// <param name="rotation">Rotation.</param> public LevelItem(Device dev, Attach attach, Vertex position, Rotation rotation, int index, EditorItemSelection selectionManager) : base(selectionManager) { this.index = index; COL = new COL { Model = new NJS_OBJECT { Attach = attach, Position = position, Rotation = rotation } }; Visible = true; Solid = true; COL.CalculateBounds(); Mesh = COL.Model.Attach.CreateD3DMesh(dev); Paste(); }
public static void Draw_HISTOGRAM_BAR_X(float _x, float _y, float _w, float _h, Color _col_MIN, Color _col_MAX, float _gutterRatio, bool _alphaFade, params float[] _values) { int _COUNT = _values.Length; float _BAR_SPACE = _w * _gutterRatio; float _BAR_THICKNESS = _BAR_SPACE / _COUNT; float _GUTTER = (_w - _BAR_SPACE) / (_COUNT - 1); for (int i = 0; i < _COUNT; i++) { float _BIN_VALUE = _values[i]; Color _COL = Color.Lerp(_col_MIN, _col_MAX, _BIN_VALUE); GL_DRAW.Draw_RECT_FILL( _x + ((_BAR_THICKNESS * i) + (_GUTTER * i)), _y, _BAR_THICKNESS, _h * _BIN_VALUE, (_alphaFade) ? COL.Set_alphaStrength(_COL, _BIN_VALUE) : _COL); } }
private void connect_Click(object sender, EventArgs e) { DateTime beforDT = DateTime.Now; string con; //获取数据库信息 con = "Server=" + server.Text.ToString() + ";Database=" + database.Text.ToString() + ";user id=" + username.Text.ToString() + ";password="******";"; //获取数据库信息 con1 = new SqlConnection(con); //连接数据库 try //连接异常处理 { con1.Open(); } catch { MessageBox.Show("Error!"); return; } tabname = tablename.Text.ToString(); //获取目标表名 select = "select * from " + tabname + ";"; //构造查询 //Console.WriteLine("123"); myda = new SqlDataAdapter(select, con); //查询所有数据 date1 = new DataSet(); myda.Fill(date1, tabname); DataColumn[] keys = new DataColumn[1]; keys[0] = date1.Tables[0].Columns["id"]; date1.Tables[0].PrimaryKey = keys; dataGridView1.DataSource = date1.Tables[0]; //将dt的第 0 个表显示到 datagridview1 ROW.Text = date1.Tables[0].Rows.Count.ToString(); //显示最大行数 COL.Text = date1.Tables[0].Columns.Count.ToString(); //显示最大列数 ROW.Show(); COL.Show(); DateTime afterDT = DateTime.Now; TimeSpan ts = afterDT.Subtract(beforDT); //MessageBox.Show("水印添加完成!"); Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds); }
public SCREEN_EXAMPLE1() { duration = 30f; title = "test"; P = COL.Get_Palette(0); // data sprawls sprawls = new List <DataSprawl>(); int _minRows = 5; int _maxRows = 20; int _minRowLength = 10; int _maxRowLength = 50; int _minTickRate = 5; int _maxTickRate = 20; int _minCellRate = 4; int _maxCellRate = 10; for (int i = 0; i < totalSprawls; i++) { sprawls.Add(new DataSprawl( Random.Range(_minRows, _maxRows), Random.Range(_minRowLength, _maxRowLength), Random.Range(_minTickRate, _maxTickRate), Random.Range(_minCellRate, _maxCellRate) )); } // partitions float gutterRatio = 1; partitionList = new List <Partitions>(); for (int i = 0; i < partitionListCount; i++) { partitionList.Add(new Partitions(Random.Range(3, 10), 0.7f)); } }
/** * 指定のユーザー番目の列文字を返す * @return 文字列 */ string getLabelsText(int idx, COL col) { return labels[idx][(int)col].Text; }
/** 指定のユーザー番目の指定の列に文字を設定する*/ void setLabelsText(int idx, COL col, string data) { labels[idx][(int)col].Text = data; }
public ScorePeak(COL.MassLib.MSPoint argMSPoint, GlycoLib.GlycanCompound argComposition) { _pt = argMSPoint; _comp = argComposition; }
static void Main(string[] args) { string filename; if (args.Length > 0) { filename = args[0]; Console.WriteLine("File: {0}", filename); } else { Console.Write("File: "); filename = Console.ReadLine(); } LandTable level = LandTable.LoadFromFile(filename); Dictionary <string, Attach> visitedAttaches = new Dictionary <string, Attach>(); switch (level.Format) { case LandTableFormat.SA1: { List <COL> newcollist = new List <COL>(); foreach (COL col in level.COL.Where((col) => col.Model != null && col.Model.Attach != null)) { if ((col.SurfaceFlags & SurfaceFlags.Visible) == SurfaceFlags.Visible) { COL newcol = new COL() { Bounds = col.Bounds }; newcol.SurfaceFlags = SurfaceFlags.Visible; newcol.Model = new NJS_OBJECT() { Name = col.Model.Name + "_cnk" }; newcol.Model.Position = col.Model.Position; newcol.Model.Rotation = col.Model.Rotation; newcol.Model.Scale = col.Model.Scale; BasicAttach basatt = (BasicAttach)col.Model.Attach; string newname = basatt.Name + "_cnk"; if (visitedAttaches.ContainsKey(newname)) { newcol.Model.Attach = visitedAttaches[newname]; } else { ChunkAttach cnkatt = new ChunkAttach(true, true) { Name = basatt.Name + "_cnk", Bounds = basatt.Bounds }; visitedAttaches[newname] = cnkatt; newcol.Model.Attach = cnkatt; VertexChunk vcnk; bool hasnormal = basatt.Normal?.Length > 0; bool hasvcolor = basatt.Mesh.Any(a => a.VColor != null); if (hasvcolor) { vcnk = new VertexChunk(ChunkType.Vertex_VertexDiffuse8); } else if (hasnormal) { vcnk = new VertexChunk(ChunkType.Vertex_VertexNormal); } else { vcnk = new VertexChunk(ChunkType.Vertex_Vertex); } List <CachedVertex> cache = new List <CachedVertex>(basatt.Vertex.Length); List <List <Strip> > strips = new List <List <Strip> >(); List <List <List <UV> > > uvs = new List <List <List <UV> > >(); foreach (NJS_MESHSET mesh in basatt.Mesh) { List <Strip> polys = new List <Strip>(); List <List <UV> > us = null; bool hasUV = mesh.UV != null; bool hasVColor = mesh.VColor != null; int currentstriptotal = 0; switch (mesh.PolyType) { case Basic_PolyType.Triangles: { List <ushort> tris = new List <ushort>(); Dictionary <ushort, UV> uvmap = new Dictionary <ushort, UV>(); foreach (Poly poly in mesh.Poly) { for (int i = 0; i < 3; i++) { ushort ind = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White, mesh.UV?[currentstriptotal])); if (hasUV) { uvmap[ind] = mesh.UV[currentstriptotal]; } ++currentstriptotal; tris.Add(ind); } } if (hasUV) { us = new List <List <UV> >(); } nvStripifier.GenerateStrips(tris.ToArray(), out var primitiveGroups); // Add strips for (var i = 0; i < primitiveGroups.Length; i++) { var primitiveGroup = primitiveGroups[i]; System.Diagnostics.Debug.Assert(primitiveGroup.Type == PrimitiveType.TriangleStrip); var stripIndices = new ushort[primitiveGroup.Indices.Length]; List <UV> stripuv = new List <UV>(); for (var j = 0; j < primitiveGroup.Indices.Length; j++) { var vertexIndex = primitiveGroup.Indices[j]; stripIndices[j] = vertexIndex; if (hasUV) { stripuv.Add(uvmap[vertexIndex]); } } polys.Add(new Strip(stripIndices, false)); if (hasUV) { us.Add(stripuv); } } } break; case Basic_PolyType.Quads: { List <ushort> tris = new List <ushort>(); Dictionary <ushort, UV> uvmap = new Dictionary <ushort, UV>(); foreach (Poly poly in mesh.Poly) { ushort[] quad = new ushort[4]; for (int i = 0; i < 4; i++) { ushort ind = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White, mesh.UV?[currentstriptotal])); if (hasUV) { uvmap[ind] = mesh.UV[currentstriptotal]; } ++currentstriptotal; quad[i] = ind; } tris.Add(quad[0]); tris.Add(quad[1]); tris.Add(quad[2]); tris.Add(quad[2]); tris.Add(quad[1]); tris.Add(quad[3]); } if (hasUV) { us = new List <List <UV> >(); } nvStripifier.GenerateStrips(tris.ToArray(), out var primitiveGroups); // Add strips for (var i = 0; i < primitiveGroups.Length; i++) { var primitiveGroup = primitiveGroups[i]; System.Diagnostics.Debug.Assert(primitiveGroup.Type == PrimitiveType.TriangleStrip); var stripIndices = new ushort[primitiveGroup.Indices.Length]; List <UV> stripuv = new List <UV>(); for (var j = 0; j < primitiveGroup.Indices.Length; j++) { var vertexIndex = primitiveGroup.Indices[j]; stripIndices[j] = vertexIndex; if (hasUV) { stripuv.Add(uvmap[vertexIndex]); } } polys.Add(new Strip(stripIndices, false)); if (hasUV) { us.Add(stripuv); } } } break; case Basic_PolyType.NPoly: case Basic_PolyType.Strips: if (hasUV) { us = new List <List <UV> >(); } foreach (Strip poly in mesh.Poly.Cast <Strip>()) { List <UV> stripuv = new List <UV>(); ushort[] inds = (ushort[])poly.Indexes.Clone(); for (int i = 0; i < poly.Indexes.Length; i++) { inds[i] = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White)); if (hasUV) { stripuv.Add(mesh.UV[currentstriptotal]); } ++currentstriptotal; } polys.Add(new Strip(inds, poly.Reversed)); if (hasUV) { us.Add(stripuv); } } break; } strips.Add(polys); uvs.Add(us); } foreach (var item in cache) { vcnk.Vertices.Add(item.vertex); if (hasnormal) { vcnk.Normals.Add(item.normal); } if (hasvcolor) { vcnk.Diffuse.Add(item.color); } } vcnk.VertexCount = (ushort)cache.Count; switch (vcnk.Type) { case ChunkType.Vertex_Vertex: vcnk.Size = (ushort)(vcnk.VertexCount * 3 + 1); break; case ChunkType.Vertex_VertexDiffuse8: vcnk.Size = (ushort)(vcnk.VertexCount * 4 + 1); break; case ChunkType.Vertex_VertexNormal: vcnk.Size = (ushort)(vcnk.VertexCount * 6 + 1); break; case ChunkType.Vertex_VertexNormalDiffuse8: vcnk.Size = (ushort)(vcnk.VertexCount * 7 + 1); break; } cnkatt.Vertex.Add(vcnk); for (int i = 0; i < basatt.Mesh.Count; i++) { NJS_MESHSET mesh = basatt.Mesh[i]; NJS_MATERIAL mat = null; if (basatt.Material != null && mesh.MaterialID < basatt.Material.Count) { mat = basatt.Material[mesh.MaterialID]; cnkatt.Poly.Add(new PolyChunkTinyTextureID() { ClampU = mat.ClampU, ClampV = mat.ClampV, FilterMode = mat.FilterMode, FlipU = mat.FlipU, FlipV = mat.FlipV, SuperSample = mat.SuperSample, TextureID = (ushort)mat.TextureID }); cnkatt.Poly.Add(new PolyChunkMaterial() { SourceAlpha = mat.SourceAlpha, DestinationAlpha = mat.DestinationAlpha, Diffuse = mat.DiffuseColor, Specular = mat.SpecularColor, SpecularExponent = (byte)mat.Exponent }); } PolyChunkStrip strip; if (mesh.UV != null) { strip = new PolyChunkStrip(ChunkType.Strip_StripUVN); } else { strip = new PolyChunkStrip(ChunkType.Strip_Strip); } if (mat != null) { strip.IgnoreLight = mat.IgnoreLighting; strip.IgnoreSpecular = mat.IgnoreSpecular; strip.UseAlpha = mat.UseAlpha; strip.DoubleSide = mat.DoubleSided; strip.FlatShading = mat.FlatShading; strip.EnvironmentMapping = mat.EnvironmentMap; } for (int i1 = 0; i1 < strips[i].Count; i1++) { Strip item = strips[i][i1]; UV[] uv2 = null; if (mesh.UV != null) { uv2 = uvs[i][i1].ToArray(); } strip.Strips.Add(new PolyChunkStrip.Strip(item.Reversed, item.Indexes, uv2, null)); } cnkatt.Poly.Add(strip); } } newcollist.Add(newcol); } if ((col.SurfaceFlags & ~SurfaceFlags.Visible) != 0) { col.SurfaceFlags &= ~SurfaceFlags.Visible; newcollist.Add(col); } } level.COL = newcollist; } level.Anim = new List <GeoAnimData>(); level.SaveToFile(System.IO.Path.ChangeExtension(filename, "sa2lvl"), LandTableFormat.SA2); break; case LandTableFormat.SA2: Vertex[] VertexBuffer = new Vertex[0]; Vertex[] NormalBuffer = new Vertex[0]; Color?[] ColorBuffer = new Color?[0]; foreach (COL col in level.COL.Where((col) => col.Model != null && col.Model.Attach is ChunkAttach)) { ChunkAttach cnkatt = (ChunkAttach)col.Model.Attach; BasicAttach basatt = new BasicAttach() { Name = cnkatt.Name, Bounds = cnkatt.Bounds }; if (cnkatt.Vertex != null) { foreach (VertexChunk chunk in cnkatt.Vertex) { if (VertexBuffer.Length < chunk.IndexOffset + chunk.VertexCount) { Array.Resize(ref VertexBuffer, chunk.IndexOffset + chunk.VertexCount); Array.Resize(ref NormalBuffer, chunk.IndexOffset + chunk.VertexCount); Array.Resize(ref ColorBuffer, chunk.IndexOffset + chunk.VertexCount); } Array.Copy(chunk.Vertices.ToArray(), 0, VertexBuffer, chunk.IndexOffset, chunk.Vertices.Count); Array.Copy(chunk.Normals.ToArray(), 0, NormalBuffer, chunk.IndexOffset, chunk.Normals.Count); if (chunk.Diffuse.Count > 0) { Array.Copy(chunk.Diffuse.Cast <Color?>().ToArray(), 0, ColorBuffer, chunk.IndexOffset, chunk.Diffuse.Count); } } } NJS_MATERIAL material = new NJS_MATERIAL() { UseTexture = true }; int minVtx = int.MaxValue; int maxVtx = int.MinValue; foreach (PolyChunk chunk in cnkatt.Poly) { switch (chunk.Type) { case ChunkType.Bits_BlendAlpha: { PolyChunkBitsBlendAlpha c2 = (PolyChunkBitsBlendAlpha)chunk; material.SourceAlpha = c2.SourceAlpha; material.DestinationAlpha = c2.DestinationAlpha; } break; case ChunkType.Bits_MipmapDAdjust: break; case ChunkType.Bits_SpecularExponent: material.Exponent = ((PolyChunkBitsSpecularExponent)chunk).SpecularExponent; break; case ChunkType.Tiny_TextureID: case ChunkType.Tiny_TextureID2: { PolyChunkTinyTextureID c2 = (PolyChunkTinyTextureID)chunk; material.ClampU = c2.ClampU; material.ClampV = c2.ClampV; material.FilterMode = c2.FilterMode; material.FlipU = c2.FlipU; material.FlipV = c2.FlipV; material.SuperSample = c2.SuperSample; material.TextureID = c2.TextureID; } break; case ChunkType.Material_Diffuse: case ChunkType.Material_Ambient: case ChunkType.Material_DiffuseAmbient: case ChunkType.Material_Specular: case ChunkType.Material_DiffuseSpecular: case ChunkType.Material_AmbientSpecular: case ChunkType.Material_DiffuseAmbientSpecular: case ChunkType.Material_Diffuse2: case ChunkType.Material_Ambient2: case ChunkType.Material_DiffuseAmbient2: case ChunkType.Material_Specular2: case ChunkType.Material_DiffuseSpecular2: case ChunkType.Material_AmbientSpecular2: case ChunkType.Material_DiffuseAmbientSpecular2: { PolyChunkMaterial c2 = (PolyChunkMaterial)chunk; material.SourceAlpha = c2.SourceAlpha; material.DestinationAlpha = c2.DestinationAlpha; if (c2.Diffuse.HasValue) { material.DiffuseColor = c2.Diffuse.Value; } if (c2.Specular.HasValue) { material.SpecularColor = c2.Specular.Value; material.Exponent = c2.SpecularExponent; } } break; case ChunkType.Strip_Strip: case ChunkType.Strip_StripUVN: case ChunkType.Strip_StripUVH: case ChunkType.Strip_StripNormal: case ChunkType.Strip_StripUVNNormal: case ChunkType.Strip_StripUVHNormal: case ChunkType.Strip_StripColor: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: case ChunkType.Strip_Strip2: case ChunkType.Strip_StripUVN2: case ChunkType.Strip_StripUVH2: { PolyChunkStrip c2 = (PolyChunkStrip)chunk; material.DoubleSided = c2.DoubleSide; material.EnvironmentMap = c2.EnvironmentMapping; material.FlatShading = c2.FlatShading; material.IgnoreLighting = c2.IgnoreLight; material.IgnoreSpecular = c2.IgnoreSpecular; material.UseAlpha = c2.UseAlpha; bool hasVColor = false; switch (chunk.Type) { case ChunkType.Strip_StripColor: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: hasVColor = true; break; } bool hasUV = false; switch (chunk.Type) { case ChunkType.Strip_StripUVN: case ChunkType.Strip_StripUVH: case ChunkType.Strip_StripUVNColor: case ChunkType.Strip_StripUVHColor: case ChunkType.Strip_StripUVN2: case ChunkType.Strip_StripUVH2: hasUV = true; break; } bool hasVertVColor = false; if (!hasVColor && c2.Strips.All(a => a.Indexes.All(b => ColorBuffer[b].HasValue))) { hasVertVColor = true; } List <Strip> strips = new List <Strip>(c2.StripCount); List <UV> uvs = hasUV ? new List <UV>() : null; List <Color> vcolors = hasVColor || hasVertVColor ? new List <Color>() : null; foreach (PolyChunkStrip.Strip strip in c2.Strips) { minVtx = Math.Min(minVtx, strip.Indexes.Min()); maxVtx = Math.Max(maxVtx, strip.Indexes.Max()); strips.Add(new Strip((ushort[])strip.Indexes.Clone(), strip.Reversed)); if (hasUV) { uvs.AddRange(strip.UVs); } if (hasVColor) { vcolors.AddRange(strip.VColors); } else if (hasVertVColor) { foreach (short i in strip.Indexes) { vcolors.Add(ColorBuffer[i].Value); } } } NJS_MESHSET mesh = new NJS_MESHSET(strips.ToArray(), false, hasUV, hasVColor || hasVertVColor); if (hasUV) { uvs.CopyTo(mesh.UV); } if (hasVColor || hasVertVColor) { vcolors.CopyTo(mesh.VColor); } mesh.MaterialID = (ushort)basatt.Material.Count; basatt.Mesh.Add(mesh); basatt.Material.Add(material); material = new NJS_MATERIAL(material.GetBytes(), 0); } break; } } int numVtx = maxVtx - minVtx + 1; basatt.ResizeVertexes(numVtx); Array.Copy(VertexBuffer, minVtx, basatt.Vertex, 0, numVtx); Array.Copy(NormalBuffer, minVtx, basatt.Normal, 0, numVtx); foreach (NJS_MESHSET mesh in basatt.Mesh) { foreach (Poly poly in mesh.Poly) { for (int i = 0; i < poly.Indexes.Length; i++) { poly.Indexes[i] = (ushort)(poly.Indexes[i] - minVtx); } } } col.Model.Attach = basatt; } level.Anim = new List <GeoAnimData>(); level.Flags = 8; // set LandTable to use PVM/GVM level.SaveToFile(System.IO.Path.ChangeExtension(filename, "sa1lvl"), LandTableFormat.SA1); break; } }
static void Main(string[] args) { Environment.CurrentDirectory = @"C:\SONICADVENTUREDX\Projects\ECPort"; List <BMPInfo> textures = new List <BMPInfo>(TextureArchive.GetTextures(@"C:\SONICADVENTUREDX\system\BEACH01.PVM")); LandTable landTable = LandTable.LoadFromFile(@"Levels\Emerald Coast\Act 1\LandTable.sa1lvl"); texmap = new Dictionary <int, int>(); BMPInfo[] newtexs = TextureArchive.GetTextures(@"C:\SONICADVENTUREDX\system\BEACH03.PVM"); for (int i = 0; i < newtexs.Length; i++) { BMPInfo found = textures.FirstOrDefault(a => a.Name.Equals(newtexs[i].Name)); if (found == null) { texmap[i] = textures.Count; textures.Add(newtexs[i]); } else { texmap[i] = textures.IndexOf(found); } } foreach (COL col in LandTable.LoadFromFile(@"Levels\Emerald Coast\Act 3\LandTable.sa1lvl").COL) { foreach (NJS_MATERIAL mat in ((BasicAttach)col.Model.Attach).Material) { mat.TextureID = texmap[mat.TextureID]; } landTable.COL.Add(col); } texmap = new Dictionary <int, int>(); newtexs = TextureArchive.GetTextures(@"C:\SONICADVENTUREDX\system\BEACH02.PVM"); for (int i = 0; i < newtexs.Length; i++) { BMPInfo found = textures.FirstOrDefault(a => a.Name.Equals(newtexs[i].Name)); if (found == null) { texmap[i] = textures.Count; textures.Add(newtexs[i]); } else { texmap[i] = textures.IndexOf(found); } } foreach (COL col in LandTable.LoadFromFile(@"Levels\Emerald Coast\Act 2\LandTable.sa1lvl").COL) { col.Bounds.Center.Z -= 2000; col.Model.Position.Z -= 2000; foreach (NJS_MATERIAL mat in ((BasicAttach)col.Model.Attach).Material) { mat.TextureID = texmap[mat.TextureID]; } landTable.COL.Add(col); } texmap = new Dictionary <int, int>(); newtexs = TextureArchive.GetTextures(@"C:\SONICADVENTUREDX\system\OBJ_BEACH.PVM"); for (int i = 0; i < newtexs.Length; i++) { BMPInfo found = textures.FirstOrDefault(a => a.Name.Equals(newtexs[i].Name)); if (found == null) { texmap[i] = textures.Count; textures.Add(newtexs[i]); } else { texmap[i] = textures.IndexOf(found); } } PAKFile pak = new PAKFile(); List <byte> inf = new List <byte>(); string filenoext = "beach01"; string longdir = "..\\..\\..\\sonic2\\resource\\gd_pc\\prs\\" + filenoext; using (System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel()) using (Direct3D d3d = new Direct3D()) using (Device dev = new Device(d3d, 0, DeviceType.Hardware, panel.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(640, 480))) { for (int i = 0; i < textures.Count; i++) { using (Texture tex = textures[i].Image.ToTexture(dev)) using (DataStream str = Surface.ToStream(tex.GetSurfaceLevel(0), ImageFileFormat.Dds)) using (MemoryStream ms = new MemoryStream()) { str.CopyTo(ms); pak.Files.Add(new PAKFile.File(filenoext + '\\' + Path.ChangeExtension(textures[i].Name, ".dds"), longdir + '\\' + Path.ChangeExtension(textures[i].Name, ".dds"), ms.ToArray())); } int infsz = inf.Count; inf.AddRange(Encoding.ASCII.GetBytes(Path.ChangeExtension(textures[i].Name, null))); inf.AddRange(new byte[0x1C - (inf.Count - infsz)]); inf.AddRange(BitConverter.GetBytes(i + 200)); inf.AddRange(BitConverter.GetBytes(0)); inf.AddRange(BitConverter.GetBytes(0)); inf.AddRange(BitConverter.GetBytes(0)); inf.AddRange(BitConverter.GetBytes(textures[i].Image.Width)); inf.AddRange(BitConverter.GetBytes(textures[i].Image.Height)); inf.AddRange(BitConverter.GetBytes(0)); inf.AddRange(BitConverter.GetBytes(0x80000000)); } } pak.Files.Insert(0, new PAKFile.File(filenoext + '\\' + filenoext + ".inf", longdir + '\\' + filenoext + ".inf", inf.ToArray())); pak.Save(@"C:\Program Files (x86)\Steam\steamapps\common\Sonic Adventure 2\mods\Emerald Coast\gd_PC\PRS\beach01.pak"); List <COL> newcollist = new List <COL>(); Dictionary <string, Attach> visitedAttaches = new Dictionary <string, Attach>(); foreach (COL col in landTable.COL.Where((col) => col.Model != null && col.Model.Attach != null)) { ConvertCOL(newcollist, visitedAttaches, col); } landTable.COL = newcollist; Console.WriteLine("Loading Object Definitions:"); Console.WriteLine("Parsing..."); LevelData.ObjDefs = new List <ObjectDefinition>(); Dictionary <string, ObjectData> objdefini = IniSerializer.Deserialize <Dictionary <string, ObjectData> >("objdefs.ini"); List <ObjectData> objectErrors = new List <ObjectData>(); ObjectListEntry[] objlstini = ObjectList.Load(@"Levels\Emerald Coast\Object List.ini", false); Directory.CreateDirectory("dllcache").Attributes |= FileAttributes.Hidden; List <KeyValuePair <string, string> > compileErrors = new List <KeyValuePair <string, string> >(); for (int ID = 0; ID < objlstini.Length; ID++) { string codeaddr = objlstini[ID].CodeString; if (!objdefini.ContainsKey(codeaddr)) { codeaddr = "0"; } ObjectData defgroup = objdefini[codeaddr]; ObjectDefinition def; if (!string.IsNullOrEmpty(defgroup.CodeFile)) { Console.WriteLine("Compiling: " + defgroup.CodeFile); def = CompileObjectDefinition(defgroup, out bool errorOccured, out string errorText); if (errorOccured) { KeyValuePair <string, string> errorValue = new KeyValuePair <string, string>( defgroup.CodeFile, errorText); compileErrors.Add(errorValue); } } else { def = new DefaultObjectDefinition(); } LevelData.ObjDefs.Add(def); // The only reason .Model is checked for null is for objects that don't yet have any // models defined for them. It would be annoying seeing that error all the time! if (string.IsNullOrEmpty(defgroup.CodeFile) && !string.IsNullOrEmpty(defgroup.Model)) { Console.WriteLine("Loading: " + defgroup.Model); // Otherwise, if the model file doesn't exist and/or no texture file is defined, // load the "default object" instead ("?"). if (!File.Exists(defgroup.Model)) { ObjectData error = new ObjectData { Name = defgroup.Name, Model = defgroup.Model, Texture = defgroup.Texture }; objectErrors.Add(error); defgroup.Model = null; } } def.Init(defgroup, objlstini[ID].Name); def.SetInternalName(objlstini[ID].Name); } // Checks if there have been any errors added to the error list and does its thing // This thing is a mess. If anyone can think of a cleaner way to do this, be my guest. if (objectErrors.Count > 0) { int count = objectErrors.Count; List <string> errorStrings = new List <string> { "The following objects failed to load:" }; foreach (ObjectData o in objectErrors) { bool texEmpty = string.IsNullOrEmpty(o.Texture); bool texExists = (!string.IsNullOrEmpty(o.Texture) && LevelData.Textures.ContainsKey(o.Texture)); errorStrings.Add(""); errorStrings.Add("Object:\t\t" + o.Name); errorStrings.Add("\tModel:"); errorStrings.Add("\t\tName:\t" + o.Model); errorStrings.Add("\t\tExists:\t" + File.Exists(o.Model)); errorStrings.Add("\tTexture:"); errorStrings.Add("\t\tName:\t" + ((texEmpty) ? "(N/A)" : o.Texture)); errorStrings.Add("\t\tExists:\t" + texExists); } // TODO: Proper logging. Who knows where this file may end up File.WriteAllLines("SADXLVL2.log", errorStrings.ToArray()); } // Loading SET Layout Console.WriteLine("Loading SET items", "Initializing..."); List <SETItem> setlist = new List <SETItem>(); SonicRetro.SAModel.SAEditorCommon.UI.EditorItemSelection selection = new SonicRetro.SAModel.SAEditorCommon.UI.EditorItemSelection(); if (LevelData.ObjDefs.Count > 0) { string setstr = @"C:\SONICADVENTUREDX\Projects\ECPort\system\SET0100S.BIN"; if (File.Exists(setstr)) { Console.WriteLine("SET: " + setstr.Replace(Environment.CurrentDirectory, "")); setlist = SETItem.Load(setstr, selection); } setstr = @"C:\SONICADVENTUREDX\Projects\ECPort\system\SET0102B.BIN"; if (File.Exists(setstr)) { Console.WriteLine("SET: " + setstr.Replace(Environment.CurrentDirectory, "")); setlist.AddRange(SETItem.Load(setstr, selection)); } setstr = @"C:\SONICADVENTUREDX\Projects\ECPort\system\SET0101S.BIN"; if (File.Exists(setstr)) { Console.WriteLine("SET: " + setstr.Replace(Environment.CurrentDirectory, "")); List <SETItem> newlist = SETItem.Load(setstr, selection); foreach (SETItem item in newlist) { item.Position.Z -= 2000; } setlist.AddRange(newlist); } } MatrixStack transform = new MatrixStack(); List <SETItem> add = new List <SETItem>(); List <SETItem> del = new List <SETItem>(); List <PalmtreeData> trees = new List <PalmtreeData>(); foreach (SETItem item in setlist) { switch (item.ID) { case 0xD: // item box item.ID = 0xA; item.Scale.X = itemboxmap[(int)item.Scale.X]; break; case 0x15: // ring group to rings for (int i = 0; i < Math.Min(item.Scale.X + 1, 8); i++) { if (item.Scale.Z == 1) // circle { double v4 = i * 360.0; Vector3 v7 = new Vector3( ObjectHelper.NJSin((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y, 0, ObjectHelper.NJCos((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y); transform.Push(); transform.NJTranslate(item.Position); transform.NJRotateObject(item.Rotation); Vector3 pos = Vector3.TransformCoordinate(v7, transform.Top); transform.Pop(); add.Add(new SETItem(0, selection) { Position = pos.ToVertex() }); } else // line { transform.Push(); transform.NJTranslate(item.Position); transform.NJRotateObject(item.Rotation); double v5; if (i % 2 == 1) { v5 = i * item.Scale.Y * -0.5; } else { v5 = Math.Ceiling(i * 0.5) * item.Scale.Y; } Vector3 pos = Vector3.TransformCoordinate(new Vector3(0, 0, (float)v5), transform.Top); transform.Pop(); add.Add(new SETItem(0, selection) { Position = pos.ToVertex() }); } } del.Add(item); break; case 0x1A: // tikal -> omochao item.ID = 0x19; item.Position.Y += 3; break; case 0x1D: // kiki item.ID = 0x5B; item.Rotation = new Rotation(); item.Scale = new Vertex(); break; case 0x1F: // sweep ->beetle item.ID = 0x38; item.Rotation = new Rotation(); item.Scale = new Vertex(1, 0, 0); break; case 0x28: // launch ramp item.ID = 6; item.Scale.X /= 2.75f; item.Scale.Z = 0.799999952316284f; break; case 0x4F: // updraft item.ID = 0x35; item.Scale.X = Math.Max(Math.Min(item.Scale.X, 200), 10) / 2; item.Scale.Y = Math.Max(Math.Min(item.Scale.Y, 200), 10) / 2; item.Scale.Z = Math.Max(Math.Min(item.Scale.Z, 200), 10) / 2; break; case 0x52: // item box air item.ID = 0xB; item.Scale.X = itemboxmap[(int)item.Scale.X]; break; // palm trees case 32: case 33: case 34: case 35: trees.Add(new PalmtreeData((byte)(item.ID - 32), item.Position, item.Rotation)); del.Add(item); break; // nonsolid objects case 47: case 48: case 49: case 50: case 51: case 52: case 59: case 62: case 63: case 64: case 70: ConvertSETItem(newcollist, item, false, setlist.IndexOf(item)); del.Add(item); break; // solid objects case 36: case 37: case 39: case 41: case 42: case 43: case 44: case 45: case 46: case 54: case 58: case 66: case 71: case 72: case 73: case 74: ConvertSETItem(newcollist, item, true, setlist.IndexOf(item)); del.Add(item); break; case 81: // goal item.ID = 0xE; item.Position.Y += 30; break; default: if (idmap.ContainsKey(item.ID)) { item.ID = idmap[item.ID]; } else { del.Add(item); } break; } } setlist.AddRange(add); foreach (SETItem item in del) { setlist.Remove(item); } setlist.Add(new SETItem(0x55, selection) { Position = new Vertex(6158.6f, -88f, 2384.97f), Scale = new Vertex(3, 0, 0) }); { COL col = new COL() { Model = new ModelFile(@"E:\Bridge Model.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Visible }; col.Model.Position = new Vertex(2803, -1, 365); foreach (NJS_MATERIAL mat in ((BasicAttach)col.Model.Attach).Material) { mat.TextureID = texmap[mat.TextureID]; } col.Model.ProcessVertexData(); col.CalculateBounds(); ConvertCOL(newcollist, new Dictionary <string, Attach>(), col); col = new COL() { Model = new ModelFile(@"E:\Bridge Model COL.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Solid }; col.Model.Position = new Vertex(2803, -1, 365); col.Model.ProcessVertexData(); col.CalculateBounds(); newcollist.Add(col); col = new COL() { Model = new ModelFile(@"E:\BridgeSegment0.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Solid }; col.Model.ProcessVertexData(); col.CalculateBounds(); newcollist.Add(col); col = new COL() { Model = new ModelFile(@"E:\BridgeSegment1.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Solid }; col.Model.ProcessVertexData(); col.CalculateBounds(); newcollist.Add(col); col = new COL() { Model = new ModelFile(@"E:\BridgeSegment2.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Solid }; col.Model.ProcessVertexData(); col.CalculateBounds(); newcollist.Add(col); col = new COL() { Model = new ModelFile(@"E:\BridgeSegment3.sa1mdl").Model, SurfaceFlags = SurfaceFlags.Solid }; col.Model.ProcessVertexData(); col.CalculateBounds(); newcollist.Add(col); } landTable.SaveToFile(@"C:\Program Files (x86)\Steam\steamapps\common\Sonic Adventure 2\mods\Emerald Coast\LandTable.sa2lvl", LandTableFormat.SA2); ByteConverter.BigEndian = true; SETItem.Save(setlist, @"C:\Program Files (x86)\Steam\steamapps\common\Sonic Adventure 2\mods\Emerald Coast\gd_PC\set0013_s.bin"); for (int i = 0; i < 4; i++) { ModelFile modelFile = new ModelFile($@"C:\SONICADVENTUREDX\Projects\Test\Objects\Levels\Emerald Coast\YASI{i}.sa1mdl"); foreach (BasicAttach attach in modelFile.Model.GetObjects().Where(a => a.Attach != null).Select(a => a.Attach)) { foreach (NJS_MATERIAL mat in attach.Material) { mat.TextureID = texmap[mat.TextureID]; } } modelFile.SaveToFile($@"C:\Program Files (x86)\Steam\steamapps\common\Sonic Adventure 2\mods\Emerald Coast\YASI{i}.sa1mdl"); } using (StreamWriter sw = File.CreateText(@"E:\Documents\Visual Studio 2017\Projects\LevelTest\LevelTest\pt.c")) sw.WriteLine(string.Join(",\r\n", trees)); }
private static void ConvertCOL(List <COL> newcollist, Dictionary <string, Attach> visitedAttaches, COL col) { if ((col.SurfaceFlags & SurfaceFlags.Visible) == SurfaceFlags.Visible) { BasicAttach basatt = (BasicAttach)col.Model.Attach; COL newcol = new COL() { Bounds = col.Bounds }; newcol.SurfaceFlags = SurfaceFlags.Visible; newcol.Model = new NJS_OBJECT() { Name = col.Model.Name + "_cnk" }; newcol.Model.Position = col.Model.Position; newcol.Model.Rotation = col.Model.Rotation; newcol.Model.Scale = col.Model.Scale; string newname = basatt.Name + "_cnk"; if (visitedAttaches != null && visitedAttaches.ContainsKey(newname)) { newcol.Model.Attach = visitedAttaches[newname]; } else { ChunkAttach cnkatt = new ChunkAttach(true, true) { Name = newname, Bounds = basatt.Bounds }; if (visitedAttaches != null) { visitedAttaches[newname] = cnkatt; } newcol.Model.Attach = cnkatt; VertexChunk vcnk; bool hasvcolor = basatt.Mesh.Any(a => a.VColor != null); bool hasnormal = !hasvcolor && basatt.Normal?.Length > 0; if (hasvcolor) { vcnk = new VertexChunk(ChunkType.Vertex_VertexDiffuse8); } else if (hasnormal) { vcnk = new VertexChunk(ChunkType.Vertex_VertexNormal); } else { vcnk = new VertexChunk(ChunkType.Vertex_Vertex); } List <CachedVertex> cache = new List <CachedVertex>(basatt.Vertex.Length); List <List <Strip> > strips = new List <List <Strip> >(); List <List <List <UV> > > uvs = new List <List <List <UV> > >(); foreach (NJS_MESHSET mesh in basatt.Mesh) { List <Strip> polys = new List <Strip>(); List <List <UV> > us = null; bool hasUV = mesh.UV != null; bool hasVColor = mesh.VColor != null; int currentstriptotal = 0; switch (mesh.PolyType) { case Basic_PolyType.Triangles: { List <ushort> tris = new List <ushort>(); Dictionary <ushort, UV> uvmap = new Dictionary <ushort, UV>(); foreach (Poly poly in mesh.Poly) { for (int i = 0; i < 3; i++) { ushort ind = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White, mesh.UV?[currentstriptotal])); if (hasUV) { uvmap[ind] = mesh.UV[currentstriptotal]; } ++currentstriptotal; tris.Add(ind); } } if (hasUV) { us = new List <List <UV> >(); } System.Diagnostics.Debug.Assert(nvStripifier.GenerateStrips(tris.ToArray(), out var primitiveGroups)); // Add strips for (var i = 0; i < primitiveGroups.Length; i++) { var primitiveGroup = primitiveGroups[i]; System.Diagnostics.Debug.Assert(primitiveGroup.Type == NvTriStripDotNet.PrimitiveType.TriangleStrip); var stripIndices = new ushort[primitiveGroup.Indices.Length]; List <UV> stripuv = new List <UV>(); for (var j = 0; j < primitiveGroup.Indices.Length; j++) { var vertexIndex = primitiveGroup.Indices[j]; stripIndices[j] = vertexIndex; if (hasUV) { stripuv.Add(uvmap[vertexIndex]); } } polys.Add(new Strip(stripIndices, false)); if (hasUV) { us.Add(stripuv); } } } break; case Basic_PolyType.Quads: { List <ushort> tris = new List <ushort>(); Dictionary <ushort, UV> uvmap = new Dictionary <ushort, UV>(); foreach (Poly poly in mesh.Poly) { ushort[] quad = new ushort[4]; for (int i = 0; i < 4; i++) { ushort ind = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White, mesh.UV?[currentstriptotal])); if (hasUV) { uvmap[ind] = mesh.UV[currentstriptotal]; } ++currentstriptotal; quad[i] = ind; } tris.Add(quad[0]); tris.Add(quad[1]); tris.Add(quad[2]); tris.Add(quad[2]); tris.Add(quad[1]); tris.Add(quad[3]); } if (hasUV) { us = new List <List <UV> >(); } System.Diagnostics.Debug.Assert(nvStripifier.GenerateStrips(tris.ToArray(), out var primitiveGroups)); // Add strips for (var i = 0; i < primitiveGroups.Length; i++) { var primitiveGroup = primitiveGroups[i]; System.Diagnostics.Debug.Assert(primitiveGroup.Type == NvTriStripDotNet.PrimitiveType.TriangleStrip); var stripIndices = new ushort[primitiveGroup.Indices.Length]; List <UV> stripuv = new List <UV>(); for (var j = 0; j < primitiveGroup.Indices.Length; j++) { var vertexIndex = primitiveGroup.Indices[j]; stripIndices[j] = vertexIndex; if (hasUV) { stripuv.Add(uvmap[vertexIndex]); } } polys.Add(new Strip(stripIndices, false)); if (hasUV) { us.Add(stripuv); } } } break; case Basic_PolyType.NPoly: case Basic_PolyType.Strips: if (hasUV) { us = new List <List <UV> >(); } foreach (Strip poly in mesh.Poly.Cast <Strip>()) { List <UV> stripuv = new List <UV>(); ushort[] inds = (ushort[])poly.Indexes.Clone(); for (int i = 0; i < poly.Indexes.Length; i++) { inds[i] = (ushort)cache.AddUnique(new CachedVertex( basatt.Vertex[poly.Indexes[i]], basatt.Normal[poly.Indexes[i]], hasVColor ? mesh.VColor[currentstriptotal] : Color.White)); if (hasUV) { stripuv.Add(mesh.UV[currentstriptotal]); } ++currentstriptotal; } polys.Add(new Strip(inds, poly.Reversed)); if (hasUV) { us.Add(stripuv); } } break; } strips.Add(polys); uvs.Add(us); } foreach (var item in cache) { vcnk.Vertices.Add(item.vertex); if (hasnormal) { vcnk.Normals.Add(item.normal); } if (hasvcolor) { vcnk.Diffuse.Add(item.color); } } vcnk.VertexCount = (ushort)cache.Count; switch (vcnk.Type) { case ChunkType.Vertex_Vertex: vcnk.Size = (ushort)(vcnk.VertexCount * 3 + 1); break; case ChunkType.Vertex_VertexDiffuse8: vcnk.Size = (ushort)(vcnk.VertexCount * 4 + 1); break; case ChunkType.Vertex_VertexNormal: vcnk.Size = (ushort)(vcnk.VertexCount * 6 + 1); break; } cnkatt.Vertex.Add(vcnk); for (int i = 0; i < basatt.Mesh.Count; i++) { NJS_MESHSET mesh = basatt.Mesh[i]; NJS_MATERIAL mat = null; if (basatt.Material != null && mesh.MaterialID < basatt.Material.Count) { mat = basatt.Material[mesh.MaterialID]; cnkatt.Poly.Add(new PolyChunkTinyTextureID() { ClampU = mat.ClampU, ClampV = mat.ClampV, FilterMode = mat.FilterMode, FlipU = mat.FlipU, FlipV = mat.FlipV, SuperSample = mat.SuperSample, TextureID = (ushort)mat.TextureID }); cnkatt.Poly.Add(new PolyChunkMaterial() { SourceAlpha = mat.SourceAlpha, DestinationAlpha = mat.DestinationAlpha, Diffuse = mat.DiffuseColor, Specular = mat.SpecularColor, SpecularExponent = (byte)mat.Exponent }); } PolyChunkStrip strip; if (mesh.UV != null) { strip = new PolyChunkStrip(ChunkType.Strip_StripUVN); } else { strip = new PolyChunkStrip(ChunkType.Strip_Strip); } if (mat != null) { strip.IgnoreLight = mat.IgnoreLighting; strip.IgnoreSpecular = mat.IgnoreSpecular; strip.UseAlpha = mat.UseAlpha; strip.DoubleSide = mat.DoubleSided; strip.FlatShading = mat.FlatShading; strip.EnvironmentMapping = mat.EnvironmentMap; } for (int i1 = 0; i1 < strips[i].Count; i1++) { Strip item = strips[i][i1]; UV[] uv2 = null; if (mesh.UV != null) { uv2 = uvs[i][i1].ToArray(); } strip.Strips.Add(new PolyChunkStrip.Strip(item.Reversed, item.Indexes, uv2, null)); } cnkatt.Poly.Add(strip); } } newcollist.Add(newcol); } if ((col.SurfaceFlags & ~SurfaceFlags.Visible) != 0) { int newflags = col.Flags & 0xF; if (col.SurfaceFlags.HasFlag(SurfaceFlags.Diggable)) { newflags |= 0x20; } if (col.SurfaceFlags.HasFlag(SurfaceFlags.Unclimbable)) { newflags |= 0x80; } if (col.SurfaceFlags.HasFlag(SurfaceFlags.Hurt)) { newflags |= 0x400; } if (col.SurfaceFlags.HasFlag(SurfaceFlags.CannotLand)) { newflags |= 0x1000; } col.Flags = newflags; newcollist.Add(col); } }
public void CalculateBounds() { COL.CalculateBounds(); COL.Model.Attach.CalculateBounds(); }
public void Save() { COL.CalculateBounds(); }
public override string ToString() { return(String.Join(",", collection.Select(COL => COL.ToString()))); }
/// <summary> /// Combine isotope pattern /// </summary> /// <param name="argNumberPermethlationSite"></param> /// <param name="argStartPurity"></param> /// <param name="argIntensities"></param> /// <returns></returns> public static float Estimater3(COL.GlycoLib.GlycanCompound argCompond,int argTheoreticalMonoIdx, float[] argIntensities) { double[] isotopeRatio = new double[argIntensities.Length]; for (int i = 0; i < isotopeRatio.Length; i++) { isotopeRatio[i] = 0; } ChemicalFormula MonoChemFormula = new ChemicalFormula(); MonoChemFormula.Add("C", argCompond.Carbon); MonoChemFormula.Add("H", argCompond.Hydrogen); MonoChemFormula.Add("O", argCompond.Oxygen); if (argCompond.Carbon13 != 0) { MonoChemFormula.Add("C{13}", argCompond.Carbon13); } if (argCompond.Deuterium != 0) { MonoChemFormula.Add("D", argCompond.Deuterium); } if (argCompond.Sodium != 0) { MonoChemFormula.Add("Na", argCompond.Sodium); } if (argCompond.Nitrogen != 0) { MonoChemFormula.Add("N", argCompond.Nitrogen); } double[] IsotopeDist = MonoChemFormula.GetIsotopicDistribution(10); return 0.0f; }