public BlockVertex(Vector3 position, HalfVector2 blockTextureCoordinate, HalfVector4 light, Color tint) { m_position = position; m_blockTextureCoordinate = blockTextureCoordinate; m_light = light; m_tint = new HalfVector4(tint.ToVector4()); }
//, Vector3 localLight) //private Vector3 _localLight; public BlockVertex(Vector3 position, HalfVector2 blockTextureCoordinate, float sunLight) { _position = position; _blockTextureCoordinate = blockTextureCoordinate; _sunLight = sunLight; //_localLight = localLight; }
/// <summary> /// Read HalfVector2 /// </summary> static HalfVector2 ReadHalfVector2(BinaryReader reader) { HalfVector2 vct = new HalfVector2(); vct.PackedValue = reader.ReadUInt32(); return(vct); }
public DualTextured(Vector3 position, HalfVector2 blockTextureCoordinate, HalfVector2 crackTextureCoordinate, float ambientOcclusionWeight) { _position = position; _blockTextureCoordinate = blockTextureCoordinate; _crackTextureCoordinate = crackTextureCoordinate; _ambientOcclusionWeight = ambientOcclusionWeight; }
public VertexCubeFaceLQ(ref Vector4B position, ref HalfVector2 UV, Byte textureArrayId, ref ByteColor lighting, ref HalfVector2 vertexInfo) { this.VertexInfo = vertexInfo; this.Color = lighting; this.Position = position; this.Position.W = textureArrayId; this.UV = UV; }
internal MyVertexFormatTexcoordNormalTangent(Vector2 texcoord, Vector3 normal, Vector3 tangent) { Texcoord = new HalfVector2(texcoord.X, texcoord.Y); Normal = VF_Packer.PackNormalB4(ref normal); Vector4 T = new Vector4(tangent, 1); Tangent = VF_Packer.PackTangentSignB4(ref T); }
private Single timeToLive; //in milliseconds internal ParticleVertexFormat(Vector2 initialPosition, Vector2 initialvelocity, Vector2 acceleration, HalfVector2 textureCoord, int timeCreated, int timeToLive) { this.initialPosition = initialPosition; this.initialvelocity = initialvelocity; this.acceleration = acceleration; this.textureCoord = textureCoord; this.timeCreated = timeCreated; this.timeToLive = timeToLive; }
private static HalfVector2[] GetBlockTextureMapping(float xOffset, float yOffset, float unitSize) { var mapping = new HalfVector2[4]; // contains texture mapping for the two triangles contained. mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + unitSize, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + unitSize); // 0, 1 mapping[3] = new HalfVector2(xOffset + unitSize, yOffset + unitSize); // 1,1 return mapping; }
private Single timeToLive; //in milliseconds #endregion Fields #region Constructors internal ParticleVertexFormat(Vector2 initialPosition, Vector2 initialvelocity, Vector2 acceleration, HalfVector2 textureCoord, int timeCreated, int timeToLive) { this.initialPosition = initialPosition; this.initialvelocity = initialvelocity; this.acceleration = acceleration; this.textureCoord = textureCoord; this.timeCreated = timeCreated; this.timeToLive = timeToLive; }
private static HalfVector2[] ReadArrayOfHalfVector2(BinaryReader reader) { var length = reader.ReadInt32(); var halfVector2Array = new HalfVector2[length]; for (var index = 0; index < length; ++index) { halfVector2Array[index] = ReadHalfVector2(reader); } return(halfVector2Array); }
/// <summary> /// Read array of HalfVector2 /// </summary> private static HalfVector2[] ReadArrayOfHalfVector2(BinaryReader reader) { var nCount = reader.ReadInt32(); var vectorArray = new HalfVector2[nCount]; for (var i = 0; i < nCount; ++i) { vectorArray[i] = ReadHalfVector2(reader); } return(vectorArray); }
/// <summary> /// Read array of HalfVector2 /// </summary> static HalfVector2[] ReadArrayOfHalfVector2(BinaryReader reader) { int nCount = reader.ReadInt32(); HalfVector2[] vctArr = new HalfVector2[nCount]; for (int i = 0; i < nCount; ++i) { vctArr[i] = ReadHalfVector2(reader); } return(vctArr); }
public void HalfVector2_ToVector4() { // arrange var halfVector = new HalfVector2(.5F, .25F); var expected = new Vector4(0.5f, .25F, 0, 1); // act var actual = halfVector.ToVector4(); // assert Assert.Equal(expected, actual); }
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { Limit(player); int theproj = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("SnowfallCloud"), damage, knockBack, player.whoAmI); float num12 = (float)Main.mouseX + Main.screenPosition.X; float num13 = (float)Main.mouseY + Main.screenPosition.Y; HalfVector2 half = new HalfVector2(num12, num13); Main.projectile[theproj].ai[0] = ReLogic.Utilities.ReinterpretCast.UIntAsFloat(half.PackedValue); Main.projectile[theproj].netUpdate = true; return(false); }
public void HalfVector2_Rgba32() { // arrange var halfVector = new HalfVector2(.5F, .25F); var actual = default(Rgba32); var expected = new Rgba32(128, 64, 0, 255); // act halfVector.ToRgba32(ref actual); // assert Assert.Equal(expected, actual); }
public void HalfVector2_ToBgr24() { // arrange var halfVector = new HalfVector2(.5F, .25F); var actual = default(Bgr24); var expected = new Bgr24(128, 64, 0); // act halfVector.ToBgr24(ref actual); // assert Assert.Equal(expected, actual); }
public void HalfVector2_PackFromScaledVector4() { // arrange Vector4 scaled = new HalfVector2(Vector2.One).ToScaledVector4(); uint expected = 1006648320u; var halfVector = default(HalfVector2); // act halfVector.PackFromScaledVector4(scaled); uint actual = halfVector.PackedValue; // assert Assert.Equal(expected, actual); }
public void HalfVector2_ToScaledVector4() { // arrange var halfVector = new HalfVector2(Vector2.One); // act Vector4 actual = halfVector.ToScaledVector4(); // assert Assert.Equal(1F, actual.X); Assert.Equal(1F, actual.Y); Assert.Equal(0, actual.Z); Assert.Equal(1, actual.W); }
public void HalfVector2() { // Test PackedValue Assert.Equal(0u, new HalfVector2(Vector2.Zero).PackedValue); Assert.Equal(1006648320u, new HalfVector2(Vector2.One).PackedValue); Assert.Equal(3033345638u, new HalfVector2(0.1f, -0.3f).PackedValue); // Test ToVector2 Assert.True(Equal(Vector2.Zero, new HalfVector2(Vector2.Zero).ToVector2())); Assert.True(Equal(Vector2.One, new HalfVector2(Vector2.One).ToVector2())); Assert.True(Equal(Vector2.UnitX, new HalfVector2(Vector2.UnitX).ToVector2())); Assert.True(Equal(Vector2.UnitY, new HalfVector2(Vector2.UnitY).ToVector2())); // Test ToScaledVector4. Vector4 scaled = new HalfVector2(Vector2.One).ToScaledVector4(); Assert.Equal(1F, scaled.X); Assert.Equal(1F, scaled.Y); Assert.Equal(0, scaled.Z); Assert.Equal(1, scaled.W); // Test PackFromScaledVector4. var pixel = default(HalfVector2); pixel.PackFromScaledVector4(scaled); Assert.Equal(1006648320u, pixel.PackedValue); // Test ordering float x = .5F; float y = .25F; Assert.True(Equal(new Vector4(x, y, 0, 1), new HalfVector2(x, y).ToVector4())); var rgb = default(Rgb24); var rgba = default(Rgba32); var bgr = default(Bgr24); var bgra = default(Bgra32); new HalfVector2(x, y).ToRgb24(ref rgb); Assert.Equal(rgb, new Rgb24(128, 64, 0)); new HalfVector2(x, y).ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(128, 64, 0, 255)); new HalfVector2(x, y).ToBgr24(ref bgr); Assert.Equal(bgr, new Bgr24(128, 64, 0)); new HalfVector2(x, y).ToBgra32(ref bgra); Assert.Equal(bgra, new Bgra32(128, 64, 0, 255)); }
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { int numberProjectiles = 8; // + Main.rand.Next(2); for (int i = 0; i < numberProjectiles; i++) { Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(360)); HalfVector2 half = new HalfVector2(player.Center.X + (i - (numberProjectiles / 2)) * 20, player.Center.Y - 200); int prog = Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI, ai1: ReLogic.Utilities.ReinterpretCast.UIntAsFloat(half.PackedValue)); Main.projectile[prog].netUpdate = true; IdgProjectile.Sync(prog); } return(false); }
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { if (!target.friendly && target.realLife < 0) { int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, mod.ProjectileType("WaveBeamStun"), damage, knockback, Main.player[projectile.owner].whoAmI); Main.projectile[proj].timeLeft = 300; HalfVector2 half = new HalfVector2(target.position.X, target.position.Y); Main.projectile[proj].ai[0] = ReLogic.Utilities.ReinterpretCast.UIntAsFloat(half.PackedValue); Main.projectile[proj].ai[1] = target.whoAmI; if (target.boss) { Main.projectile[proj].timeLeft = 80; } Main.projectile[proj].netUpdate = true; projectile.Kill(); } }
public bool ExportDataPackedAsHV2(string tagName, Vector2[] vctArr) { WriteTag(tagName); if (vctArr == null) { _writer.Write(0); return(true); } _writer.Write(vctArr.Length); foreach (var vector in vctArr) { var val = new HalfVector2(vector); WriteVector(val); } return(true); }
public bool ExportDataPackedAsHV2(string tagName, Vector2[] vctArr) { WriteTag(tagName); if (vctArr == null) { m_writer.Write(0); return(true); } m_writer.Write(vctArr.Length); foreach (Vector2 vctVal in vctArr) { HalfVector2 vct = new HalfVector2(vctVal); WriteVector(vct); } return(true); }
private static bool ExportDataPackedAsHV2(this BinaryWriter writer, string tagName, Vector2[] vectorArray) { WriteTag(writer, tagName); if (vectorArray == null) { writer.Write(0); return(true); } writer.Write(vectorArray.Length); foreach (var vectorVal in vectorArray) { var vector = new HalfVector2(vectorVal); WriteHalfVector2(writer, ref vector); } return(true); }
public override void AI() { if (projectile.localAI[1] == 0) { HalfVector2 half = new HalfVector2(projectile.Center.X, projectile.Center.Y); projectile.localAI[0] = ReLogic.Utilities.ReinterpretCast.UIntAsFloat(half.PackedValue); projectile.localAI[1] = 1; SGAmod.AddScreenShake(24f, 320, projectile.Center); } if (projectile.ai[0] % 1 == 0 && projectile.ai[1] > 0 && projectile.ai[0] < 12) //GetType() == typeof(SurtWaveBrimFlame)) { Vector2 where = new Vector2(Main.rand.Next(-64, 64), Main.rand.Next(-64, 64)); int proj2 = Projectile.NewProjectile(new Vector2(projectile.Center.X, projectile.Center.Y - projectile.ai[0] * 15) + where, new Vector2(0, -8), mod.ProjectileType("BoulderBlast"), (int)((float)projectile.damage * 0.75f), projectile.knockBack / 3f, projectile.owner); Main.projectile[proj2].melee = true; Main.projectile[proj2].magic = false; Main.projectile[proj2].timeLeft = 3; Main.projectile[proj2].usesLocalNPCImmunity = true; Main.projectile[proj2].localNPCHitCooldown = -1; Main.projectile[proj2].netUpdate = true; IdgProjectile.Sync(proj2); } projectile.scale += 0.2f; projectile.ai[0] += 1; Vector2 basepoint = (new HalfVector2() { PackedValue = ReLogic.Utilities.ReinterpretCast.FloatAsUInt(projectile.localAI[0]) }.ToVector2()) + new Vector2(0, -8); Lighting.AddLight(basepoint, 2f * (Color.Yellow.ToVector3() * ((float)projectile.timeLeft / 24f))); Lighting.AddLight(projectile.Center, Color.Yellow.ToVector3()); if (projectile.ai[0] < 4) { int thisoned = Projectile.NewProjectile(new Vector2(projectile.Center.X, basepoint.Y), new Vector2(Main.rand.NextFloat(-5f, 5f), Main.rand.NextFloat(-8f, -3f) - (projectile.ai[0] / 0.75f)), ModContent.ProjectileType <SurtRocks>(), projectile.damage * 6, projectile.knockBack * 2f, Main.player[projectile.owner].whoAmI); IdgProjectile.Sync(thisoned); } }
public PseudoFullObjectState(GameObject obj, bool destroyed = false) { ObjectId = obj.ObjectId; VelocityChanged = true; PositionChanged = true; RotationChanged = true; RotationVelocityChanged = true; RestitutionChanged = true; SizeChanged = true; IsSensorObject = obj.IsSensor; IsStaticObject = obj.IsStatic; WasDestroyed = destroyed; Velocity = new HalfVector2(obj.LinearVelocity); Rotation = (Half)obj.Rotation; RotationVelocity = (Half)obj.AngularVelocity; Position = obj.Position; Restitution = (Half)obj.Restitution; Size = new HalfVector2(obj.Size); }
public PseudoFullObjectState(PseudoFullObjectState state, bool destroyed) { if (destroyed) { ObjectId = state.ObjectId; VelocityChanged = false; PositionChanged = false; RotationChanged = false; RotationVelocityChanged = false; RestitutionChanged = false; SizeChanged = false; IsSensorObject = false; IsStaticObject = false; WasDestroyed = true; Velocity = new HalfVector2(); Rotation = 0; RotationVelocity = 0; Position = new Vector2(); Restitution = 0; Size = new HalfVector2(); } else { ObjectId = state.ObjectId; VelocityChanged = state.VelocityChanged; PositionChanged = state.PositionChanged; RotationChanged = state.RotationChanged; RotationVelocityChanged = state.RotationVelocityChanged; RestitutionChanged = state.RestitutionChanged; SizeChanged = state.SizeChanged; IsSensorObject = state.IsSensorObject; IsStaticObject = state.IsStaticObject; WasDestroyed = state.WasDestroyed; Velocity = state.Velocity; Rotation = state.Rotation; RotationVelocity = state.RotationVelocity; Position = state.Position; Restitution = state.Restitution; Size = state.Size; } }
public override void AI() { projectile.timeLeft += 2; bool cond = projectile.timeLeft == 4; for (int num621 = 0; num621 < (cond ? 15 : 1); num621++) { int num622 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 226, projectile.velocity.X * (cond ? 1.5f : 0.5f), projectile.velocity.Y * (cond ? 1.5f : 0.5f), 20, Color.Red, 0.5f); Main.dust[num622].velocity *= 1f; if (Main.rand.Next(2) == 0) { Main.dust[num622].scale = 0.5f; Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; } Main.dust[num622].noGravity = true; } Player player = Main.player[projectile.owner]; projectile.ai[0] += 1; Vector2 speedz = projectile.velocity; float atspeed = speedz.Length(); Vector2 gohere = new HalfVector2() { PackedValue = ReLogic.Utilities.ReinterpretCast.FloatAsUInt(projectile.ai[1]) }.ToVector2(); //ReLogic.Utilities.ReinterpretCast.UIntAsFloat(half.PackedValue); speedz = gohere - projectile.Center; speedz.Normalize(); speedz *= atspeed; projectile.velocity = speedz; if ((projectile.Center - gohere).Length() < atspeed + 8 || projectile.timeLeft > 300) { projectile.Kill(); } }
public override void NPCLoot(NPC npc) { if (npc.lastInteraction == 255) { //Main.NewText("Accidental Death, score unchanged"); return; } int TEScoreBoardType = TileEntityType <TEScoreBoard>(); foreach (TileEntity current in TileEntity.ByID.Values) { if (current.type == TEScoreBoardType) { //QuickBox is a neat tool for visualizing things while modding. //Dust.QuickBox(npc.position, npc.position + new Vector2(npc.width, npc.height), 1, Color.White, null); var scoreboard = current as TEScoreBoard; if (scoreboard.GetPlayArea().Intersects(npc.getRect())) { Player scoringPlayer = Main.player[npc.lastInteraction]; int score = 0; // Using HalfVector2 and ReinterpretCast.UIntAsFloat is a way to pack a Vector2 into a single float variable. HalfVector2 halfVector = new HalfVector2((current.Position.X + 1) * 16, (current.Position.Y + 1) * 16); Projectile.NewProjectile(npc.Center, Vector2.Zero, ProjectileType <Projectiles.ScorePoint>(), 0, 0, Main.myPlayer, ReLogic.Utilities.ReinterpretCast.UIntAsFloat(halfVector.PackedValue), npc.lastInteraction); scoreboard.scores.TryGetValue(scoringPlayer.name, out score); scoreboard.scores[scoringPlayer.name] = score + 1; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("{0}: {1}", scoringPlayer.name, scoreboard.scores[scoringPlayer.name]); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText(scoringPlayer.name + ": " + scoreboard.scores[scoringPlayer.name]); } scoreboard.scoresChanged = true; } } } }
public override void AI() { // Since projectiles have 2 ai slots, and I don't want to do manual syncing of an extra variable, here I use the HalfVector2 and ReinterpretCast.FloatAsUInt to get a Vector2 from 1 float variable instead of 2 like normal. Vector2 target = new HalfVector2() { PackedValue = ReLogic.Utilities.ReinterpretCast.FloatAsUInt(projectile.ai[0]) }.ToVector2(); Rectangle targetRectangle = new Rectangle((int)target.X - 4, (int)target.Y - 4, 8, 8); if (projectile.Hitbox.Intersects(targetRectangle)) { projectile.Kill(); return; } Vector2 targetDirection = new Vector2(target.X, target.Y) - projectile.Center; projectile.velocity = Vector2.Normalize(targetDirection) * 5f; // Using the player's index, which we passed into ai[1], we can differentiate kills by assigning a hue to the dust we spawn float hue = ((int)(projectile.ai[1]) % 6) / 6f; Dust.QuickDust(projectile.Center, Main.hslToRgb(hue, 1f, 0.5f)); }
internal override void GenerateNoiseHelpTexture(int storageSize, IMyModule macroModulator) { if (m_cachedNoise != null || !ENABLE_NOISE_CACHING) { return; } m_tapSize = storageSize / NOISE_RESOLUTION; Vector2 encodedPosition = Vector2.Zero; float halfDistance = 1 / (2.0f * NOISE_RESOLUTION); Vector3 encoded = Vector3.Zero; Vector3 localPos = Vector3.Zero; m_cachedNoise = new HalfVector2[(NOISE_RESOLUTION + 1) * (NOISE_RESOLUTION + 1)]; for (int i = 0; i <= NOISE_RESOLUTION; ++i) { encodedPosition.X = (i / (float)NOISE_RESOLUTION); encodedPosition.X += halfDistance; for (int j = 0; j <= NOISE_RESOLUTION; ++j) { encodedPosition.Y = (j / (float)NOISE_RESOLUTION); encodedPosition.Y += halfDistance; Decode(ref encodedPosition, ref encoded); if (encoded.X.IsValid() == false || encoded.Y.IsValid() == false || encoded.Z.IsValid() == false) { m_cachedNoise[i * (NOISE_RESOLUTION + 1) + j] = new HalfVector2(-m_hillHalfDeviation, m_canyonHalfDeviation); continue; } localPos = encoded * m_shapeAttributes.Radius; m_cachedNoise[i * (NOISE_RESOLUTION + 1) + j] = CalculateNoiseValuesAtPoint(macroModulator, ref localPos); } } }
public void HalfVector2() { //Test PackedValue Assert.AreEqual(0u, new HalfVector2(Vector2.Zero).PackedValue); Assert.AreEqual(1006648320u, new HalfVector2(Vector2.One).PackedValue); Assert.AreEqual(3033345638u, new HalfVector2(0.1f, -0.3f).PackedValue); //Test ToVector2 Assert.AreEqual(Vector2.Zero, new HalfVector2(Vector2.Zero).ToVector2()); Assert.AreEqual(Vector2.One, new HalfVector2(Vector2.One).ToVector2()); Assert.AreEqual(Vector2.UnitX, new HalfVector2(Vector2.UnitX).ToVector2()); Assert.AreEqual(Vector2.UnitY, new HalfVector2(Vector2.UnitY).ToVector2()); var x = 0.1f; var y = -0.3f; var packed = new HalfVector2(x, y).PackedValue; var unpacked = new HalfVector2() { PackedValue = packed }.ToVector2(); Assert.AreEqual(x, unpacked.X, 0.01f); Assert.AreEqual(y, unpacked.Y, 0.01f); }
private void WriteVector(HalfVector2 val) { m_writer.Write(val.PackedValue); }
internal override void GenerateNoiseHelpTexture(int storageSize, IMyModule macroModulator) { if (m_cachedNoise != null || !ENABLE_NOISE_CACHING) { return; } m_tapSize = storageSize / NOISE_RESOLUTION; Vector2 encodedPosition = Vector2.Zero; float halfDistance = 1 / (2.0f * NOISE_RESOLUTION); Vector3 encoded = Vector3.Zero; Vector3 localPos = Vector3.Zero; m_cachedNoise = new HalfVector2[(NOISE_RESOLUTION + 1) * (NOISE_RESOLUTION + 1)]; for (int i = 0; i <= NOISE_RESOLUTION; ++i) { encodedPosition.X = (i / (float)NOISE_RESOLUTION); encodedPosition.X += halfDistance; for (int j = 0; j <= NOISE_RESOLUTION; ++j) { encodedPosition.Y = (j / (float)NOISE_RESOLUTION); encodedPosition.Y += halfDistance; Decode(ref encodedPosition, ref encoded); if (encoded.X.IsValid() == false || encoded.Y.IsValid()==false || encoded.Z.IsValid()==false) { m_cachedNoise[i * (NOISE_RESOLUTION + 1) + j] = new HalfVector2(-m_hillHalfDeviation, m_canyonHalfDeviation); continue; } localPos = encoded * m_shapeAttributes.Radius; m_cachedNoise[i * (NOISE_RESOLUTION + 1) + j] = CalculateNoiseValuesAtPoint(macroModulator, ref localPos); } } }
// Sort of lazy-load, where constructor just saves information about what this model should be, but real load is done here - and only one time. // This loads only vertex data, doesn't touch GPU // Can be called from main and background thread public void LoadData() { if (m_loadedData) return; if (m_loadedContent) return; lock (this) { if (m_loadedData) return; if (m_loadedContent) return; MyRender.GetRenderProfiler().StartProfilingBlock("MyModel::LoadData"); MyRender.Log.WriteLine("MyModel.LoadData -> START", LoggingOptions.LOADING_MODELS); MyRender.Log.IncreaseIndent(LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("m_assetName: " + m_assetName, LoggingOptions.LOADING_MODELS); // Read data from model TAG parameter. There are stored vertex positions, triangle indices, vectors, ... everything we need. MyRender.GetRenderProfiler().StartProfilingBlock("Model - load data - import data"); string assetForImport = AssetName; var fsPath = Path.IsPathRooted(AssetName) ? AssetName : Path.Combine(MyFileSystem.ContentPath, AssetName); if (!MyFileSystem.FileExists(fsPath)) { MyRender.Log.WriteLine("ERROR: Asset " + AssetName + "not exists!"); assetForImport = @"Models\Debug\Error.mwm"; } MyRender.Log.WriteLine(String.Format("Importing asset {0}, path: {1}", assetForImport, AssetName), LoggingOptions.LOADING_MODELS); try { m_importer.ImportData(assetForImport); } catch { MyRender.Log.WriteLine(String.Format("Importing asset failed {0}", m_assetName)); throw; } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("Model - load data - load tag data"); Dictionary<string, object> tagData = m_importer.GetTagData(); if (tagData.Count == 0) { throw new Exception(String.Format("Uncompleted tagData for asset: {0}, path: {1}", m_assetName, AssetName)); } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("Model - load data - vertex, normals, texture coords"); object patternScale; if (tagData.TryGetValue(MyImporterConstants.TAG_PATTERN_SCALE, out patternScale)) { PatternScale = (float)patternScale; } HalfVector4[] vertices = (HalfVector4[])tagData[MyImporterConstants.TAG_VERTICES]; //Dont assert, it can be animation //System.Diagnostics.Debug.Assert(vertices.Length > 0); Byte4[] normals = (Byte4[])tagData[MyImporterConstants.TAG_NORMALS]; m_vertices = new MyCompressedVertexNormal[vertices.Length]; if (normals.Length > 0) { for (int v = 0; v < vertices.Length; v++) { m_vertices[v] = new MyCompressedVertexNormal() { Position = vertices[v],// VF_Packer.PackPosition(ref vertices[v]), Normal = normals[v]//VF_Packer.PackNormalB4(ref normals[v]) }; } } else { for (int v = 0; v < vertices.Length; v++) { m_vertices[v] = new MyCompressedVertexNormal() { Position = vertices[v],// VF_Packer.PackPosition(ref vertices[v]), }; } } m_verticesCount = vertices.Length; HalfVector2[] forLoadingTexCoords0 = (HalfVector2[])tagData[MyImporterConstants.TAG_TEXCOORDS0]; m_forLoadingTexCoords0 = new HalfVector2[forLoadingTexCoords0.Length]; for (int t = 0; t < forLoadingTexCoords0.Length; t++) { m_forLoadingTexCoords0[t] = forLoadingTexCoords0[t];// new HalfVector2(forLoadingTexCoords0[t]); m_forLoadingTexCoords0[t] = new HalfVector2(m_forLoadingTexCoords0[t].ToVector2() / PatternScale); } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("Model - load data - mesh"); m_meshContainer.Clear(); if (tagData.ContainsKey(MyImporterConstants.TAG_MESH_PARTS)) { List<int> indices = new List<int>(GetVerticesCount()); // Default capacity estimation int maxIndex = 0; List<MyMeshPartInfo> meshParts = tagData[MyImporterConstants.TAG_MESH_PARTS] as List<MyMeshPartInfo>; foreach (MyMeshPartInfo meshPart in meshParts) { if (meshPart.m_MaterialDesc != null) MyRenderModels.Materials[meshPart.m_MaterialDesc.MaterialName] = meshPart.m_MaterialDesc; MyRenderMesh mesh = new MyRenderMesh(meshPart, m_assetName); mesh.IndexStart = indices.Count; mesh.TriCount = meshPart.m_indices.Count / 3; System.Diagnostics.Debug.Assert(mesh.TriCount > 0); foreach (var i in meshPart.m_indices) { indices.Add(i); if (i > maxIndex) { maxIndex = i; } } m_meshContainer.Add(mesh); if (meshPart.m_MaterialDesc != null && meshPart.Technique == MyMeshDrawTechnique.GLASS) { float minimumGlassShadow = 0.0f; if (string.IsNullOrEmpty(meshPart.m_MaterialDesc.GlassCW)) continue; if (string.IsNullOrEmpty(meshPart.m_MaterialDesc.GlassCCW)) continue; var materialCW = MyTransparentMaterials.GetMaterial(meshPart.m_MaterialDesc.GlassCW); var materialCCW = MyTransparentMaterials.GetMaterial(meshPart.m_MaterialDesc.GlassCCW); mesh.GlassDithering = System.Math.Max(materialCW.Color.W, minimumGlassShadow); MyRenderMesh glassMesh = new MyRenderMesh(meshPart, m_assetName); glassMesh.GlassDithering = System.Math.Max(materialCCW.Color.W, minimumGlassShadow); glassMesh.IndexStart = indices.Count; glassMesh.TriCount = meshPart.m_indices.Count / 3; System.Diagnostics.Debug.Assert(glassMesh.TriCount > 0); for (int i = 0; i < meshPart.m_indices.Count; i += 3) { indices.Add(meshPart.m_indices[i + 0]); indices.Add(meshPart.m_indices[i + 2]); indices.Add(meshPart.m_indices[i + 1]); } m_meshContainer.Add(glassMesh); } } if (maxIndex <= ushort.MaxValue) { // create 16 bit indices m_Indices_16bit = new ushort[indices.Count]; for (int i = 0; i < indices.Count; i++) { m_Indices_16bit[i] = (ushort)indices[i]; } } else { // use 32bit indices m_Indices = indices.ToArray(); } m_trianglesCount = indices.Count / 3; } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("Model - load data - other data"); if (MyRenderConstants.RenderQualityProfile.UseNormals && m_forLoadingTexCoords0.Length > 0) { var verticesNum = vertices.Length; Byte4[] forLoadingTangents = (Byte4[])tagData[MyImporterConstants.TAG_TANGENTS]; Byte4[] forLoadingBitangents = (Byte4[])tagData[MyImporterConstants.TAG_BINORMALS]; m_forLoadingTangents = new Byte4[forLoadingTangents.Length]; for (int v = 0; v < forLoadingTangents.Length; v++) { var N = VF_Packer.UnpackNormal(m_vertices[v].Normal.PackedValue); var T = VF_Packer.UnpackNormal(forLoadingTangents[v].PackedValue); var B = VF_Packer.UnpackNormal(forLoadingBitangents[v].PackedValue); var tangentSign = new Vector4(T.X, T.Y, T.Z, 0); tangentSign.W = T.Cross(N).Dot(B) < 0 ? -1 : 1; m_forLoadingTangents[v] = VF_Packer.PackTangentSignB4(ref tangentSign); } } m_specularShininess = (float)tagData[MyImporterConstants.TAG_SPECULAR_SHININESS]; m_specularPower = (float)tagData[MyImporterConstants.TAG_SPECULAR_POWER]; m_rescaleFactor = (float)tagData[MyImporterConstants.TAG_RESCALE_FACTOR]; BoneIndices = (Vector4I[])tagData[MyImporterConstants.TAG_BLENDINDICES]; BoneWeights = (Vector4[])tagData[MyImporterConstants.TAG_BLENDWEIGHTS]; Animations = (ModelAnimations)tagData[MyImporterConstants.TAG_ANIMATIONS]; Bones = (MyModelBone[])tagData[MyImporterConstants.TAG_BONES]; if(BoneIndices.Length > 0 && Bones.Length > MyRenderConstants.MAX_SHADER_BONES) { List<MyMeshPartInfo> meshParts = tagData[MyImporterConstants.TAG_MESH_PARTS] as List<MyMeshPartInfo>; Dictionary<int, int> vertexChanged = new Dictionary<int,int>(); for(int p=0; p<meshParts.Count; p++) { var meshPart = meshParts[p]; Dictionary<int, int> bonesUsed = new Dictionary<int, int>(); int trianglesNum = meshPart.m_indices.Count / 3; for (int i = 0; i < trianglesNum; i++) { for (int j = 0; j < 3; j++) { int index = meshPart.m_indices[i * 3 + j]; if(BoneWeights[index].X > 0) bonesUsed[BoneIndices[index].X] = 1; if (BoneWeights[index].Y > 0) bonesUsed[BoneIndices[index].Y] = 1; if (BoneWeights[index].Z > 0) bonesUsed[BoneIndices[index].Z] = 1; if (BoneWeights[index].W > 0) bonesUsed[BoneIndices[index].W] = 1; } } var partBones = new List<int>(bonesUsed.Keys); partBones.Sort(); if (partBones.Count > 0 && partBones[partBones.Count - 1] >= MyRenderConstants.MAX_SHADER_BONES) { for(int i=0; i<partBones.Count; i++) { bonesUsed[partBones[i]] = i; } Dictionary<int, int> vertexTouched = new Dictionary<int, int>(); for (int i = 0; i < trianglesNum; i++) { for (int j = 0; j < 3; j++) { int index = meshPart.m_indices[i * 3 + j]; if(!vertexTouched.ContainsKey(index)) { if (BoneWeights[index].X > 0) BoneIndices[index].X = bonesUsed[BoneIndices[index].X]; if (BoneWeights[index].Y > 0) BoneIndices[index].Y = bonesUsed[BoneIndices[index].Y]; if (BoneWeights[index].Z > 0) BoneIndices[index].Z = bonesUsed[BoneIndices[index].Z]; if (BoneWeights[index].W > 0) BoneIndices[index].W = bonesUsed[BoneIndices[index].W]; vertexTouched[index] = 1; int changes = 0; vertexChanged.TryGetValue(index, out changes); vertexChanged[index] = changes + 1; } } } m_meshContainer[p].BonesUsed = partBones.ToArray(); } } if (vertexChanged.Values.Count > 0) Debug.Assert(vertexChanged.Values.Max() < 2, "Vertex shared between model parts, will likely result in wrong skinning"); } BoundingBox = (BoundingBox)tagData[MyImporterConstants.TAG_BOUNDING_BOX]; BoundingSphere = (BoundingSphere)tagData[MyImporterConstants.TAG_BOUNDING_SPHERE]; BoundingBoxSize = BoundingBox.Max - BoundingBox.Min; BoundingBoxSizeHalf = BoundingBoxSize / 2.0f; Dictionary<string, MyModelDummy> Dummies = tagData[MyImporterConstants.TAG_DUMMIES] as Dictionary<string, MyModelDummy>; MyRender.GetRenderProfiler().EndProfilingBlock(); if (tagData.ContainsKey(MyImporterConstants.TAG_LODS)) { var tagLODs = tagData[MyImporterConstants.TAG_LODS]; LODs.Clear(); LODs.AddArray((MyLODDescriptor[])tagLODs); foreach (var lodDesc in LODs) { if (!string.IsNullOrEmpty(lodDesc.RenderQuality)) { lodDesc.RenderQualityList = new List<int>(); string[] qualityStrings = lodDesc.RenderQuality.ToUpper().Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries); foreach (string qs in qualityStrings) { string qs2 = qs.Trim(); if (qs2 == "LOW") lodDesc.RenderQualityList.Add((int)MyRenderQualityEnum.LOW); else if (qs2 == "NORMAL") lodDesc.RenderQualityList.Add((int)MyRenderQualityEnum.NORMAL); else if (qs2 == "HIGH") lodDesc.RenderQualityList.Add((int)MyRenderQualityEnum.HIGH); else if (qs2 == "EXTREME") lodDesc.RenderQualityList.Add((int)MyRenderQualityEnum.EXTREME); } } } } MyRender.Log.WriteLine("Vertexes.Length: " + GetVerticesCount(), LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("Centered: " + (bool)tagData[MyImporterConstants.TAG_CENTERED], LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("UseChannelTextures: " + (bool)tagData[MyImporterConstants.TAG_USE_CHANNEL_TEXTURES], LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("Length in meters: " + (float)tagData[MyImporterConstants.TAG_LENGTH_IN_METERS], LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("Rescale to length in meters?: " + (bool)tagData[MyImporterConstants.TAG_RESCALE_TO_LENGTH_IN_METERS], LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("SpecularShininess: " + m_specularShininess, LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("SpecularPower: " + m_specularPower, LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("RescaleFactor: " + m_rescaleFactor, LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("BoundingBox: " + BoundingBox, LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("BoundingSphere: " + BoundingSphere, LoggingOptions.LOADING_MODELS); MyPerformanceCounter.PerAppLifetime.MyModelsCount++; MyPerformanceCounter.PerAppLifetime.MyModelsMeshesCount += m_meshContainer.Count; MyPerformanceCounter.PerAppLifetime.MyModelsVertexesCount += GetVerticesCount(); MyPerformanceCounter.PerAppLifetime.MyModelsTrianglesCount += m_trianglesCount; ModelInfo = new MyModelInfo(GetTrianglesCount(), GetVerticesCount(), BoundingBoxSize); m_loadedData = true; m_importer.Clear(); MyRender.Log.DecreaseIndent(LoggingOptions.LOADING_MODELS); MyRender.Log.WriteLine("MyModel.LoadData -> END", LoggingOptions.LOADING_MODELS); MyRender.GetRenderProfiler().EndProfilingBlock(); } }
internal MyVertexFormatPositionHTextureH(HalfVector4 position, HalfVector2 texcoord) { Position = position; Texcoord = texcoord; }
public VertexPositionVectorColorTexture(Vector3 position, Vector4 color, HalfVector2 textureCoordinate) { this.Position = position; this.Color = color; this.TextureCoordinate = textureCoordinate; }
internal MyVertexFormatPositionTextureSkinning(HalfVector4 position, HalfVector2 texcoord, Byte4 indices, Vector4 weights) { Position = position; Texcoord = texcoord; BoneIndices = indices; BoneWeights = new HalfVector4(weights); }
internal MyVertexFormatTexcoordNormalTangent(HalfVector2 texcoord, Byte4 normal, Byte4 tangent) { Texcoord = texcoord; Normal = normal; Tangent = tangent; }
private static bool ExportDataPackedAsHV2(this BinaryWriter writer, string tagName, Vector2[] vectorArray) { WriteTag(writer, tagName); if (vectorArray == null) { writer.Write(0); return true; } writer.Write(vectorArray.Length); foreach (var vectorVal in vectorArray) { var vector = new HalfVector2(vectorVal); WriteHalfVector2(writer, ref vector); } return true; }
private void AddVertex(int x, int z, Vector3 addition, HalfVector2 textureCoordinate) { VertexList.Add(new BlockVertex(new Vector3(x, 128, z) + addition, textureCoordinate, 1f)); }
//-------------------------------------------------------------- /// <summary> /// Gets the texture data of the specified mipmap level as a <see cref="Vector4"/> array. /// </summary> /// <param name="texture">The texture.</param> /// <param name="level">The mipmap level to read. Currently only 0 is supported!</param> /// <returns> /// The array containing the data of the specified mipmap level. /// (One <see cref="Vector4"/> element per pixel.) /// </returns> /// <remarks> /// <para> /// This method can be used with following texture surface formats: /// <see cref="SurfaceFormat.Alpha8"/>, <see cref="SurfaceFormat.Color"/>, /// <see cref="SurfaceFormat.Rg32"/>, <see cref="SurfaceFormat.Rgba64"/>, /// <see cref="SurfaceFormat.Single"/>, <see cref="SurfaceFormat.Vector2"/>, /// <see cref="SurfaceFormat.Vector4"/>, <see cref="SurfaceFormat.HalfSingle"/>, /// <see cref="SurfaceFormat.HalfVector2"/>, <see cref="SurfaceFormat.HalfVector4"/> /// </para> /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="texture"/> is <see langword="null"/>. /// </exception> /// <exception cref="NotImplementedException"> /// Invalid mipmap level. Extracting mipmap levels other than 0 is not yet implemented. /// </exception> /// <exception cref="NotSupportedException"> /// Texture format is not yet supported. /// </exception> public static Vector4[] GetTextureLevelVector4(Texture2D texture, int level) { if (texture == null) throw new ArgumentNullException("texture"); if (level < 0) throw new ArgumentOutOfRangeException("level"); if (level > 0) throw new NotImplementedException("GetTextureLevelVector4 for levels other than 0 is not yet implemented."); var bufferLevel0 = new Vector4[texture.Width * texture.Height]; if (texture.Format == SurfaceFormat.Alpha8) { var buffer = new byte[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = new Vector4(0, 0, 0, buffer[i] / 255.0f); } else if (texture.Format == SurfaceFormat.Color) { var buffer = new Color[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = buffer[i].ToVector4(); } else if (texture.Format == SurfaceFormat.Rg32) { var buffer = new Rg32[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) { var v = buffer[i].ToVector2(); bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0); } } else if (texture.Format == SurfaceFormat.Rgba64) { var buffer = new Rgba64[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = buffer[i].ToVector4(); } else if (texture.Format == SurfaceFormat.Single) { var buffer = new Single[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = new Vector4(buffer[i]); } else if (texture.Format == SurfaceFormat.Vector2) { var buffer = new Vector2[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = new Vector4(buffer[i].X, buffer[i].Y, 0, 0); } else if (texture.Format == SurfaceFormat.Vector4) { texture.GetData(bufferLevel0); } else if (texture.Format == SurfaceFormat.HalfSingle) { var buffer = new HalfSingle[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = new Vector4(buffer[i].ToSingle(), 0, 0, 0); } else if (texture.Format == SurfaceFormat.HalfVector2) { var buffer = new HalfVector2[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) { var v = buffer[i].ToVector2(); bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0); } } else if (texture.Format == SurfaceFormat.HalfVector4) { var buffer = new HalfVector4[bufferLevel0.Length]; texture.GetData(buffer); for (int i = 0; i < buffer.Length; i++) bufferLevel0[i] = buffer[i].ToVector4(); } else { throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported."); } return bufferLevel0; }
public static void SetTextureLevel(Texture2D texture, int level, float[] data) { if (texture == null) throw new ArgumentNullException("texture"); if (data == null) throw new ArgumentNullException("data"); if (texture.Format == SurfaceFormat.Alpha8) { var buffer = new byte[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = (byte)(data[i] * 255.0f); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.Color) { var buffer = new Color[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new Color(data[i], data[i], data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.Rg32) { var buffer = new Rg32[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new Rg32(data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.Rgba64) { var buffer = new Rgba64[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new Rgba64(data[i], data[i], data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.Single) { texture.SetData(level, null, data, 0, data.Length); } else if (texture.Format == SurfaceFormat.Vector2) { var buffer = new Vector2[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new Vector2(data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.Vector4) { var buffer = new Vector4[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new Vector4(data[i], data[i], data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.HalfSingle) { var buffer = new HalfSingle[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new HalfSingle(data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.HalfVector2) { var buffer = new HalfVector2[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new HalfVector2(data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else if (texture.Format == SurfaceFormat.HalfVector4) { var buffer = new HalfVector4[data.Length]; for (int i = 0; i < buffer.Length; i++) buffer[i] = new HalfVector4(data[i], data[i], data[i], data[i]); texture.SetData(level, null, buffer, 0, buffer.Length); } else { throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported."); } }
/// <summary> /// Calculates uv-mampings for given texture and direction. /// </summary> /// <param name="textureIndex">The asked texture's texture-index.</param> /// <param name="direction">The asked direction.</param> /// <returns>Returns list of uv-mappings for given textureIndex and face-direction.</returns> private static HalfVector2[] GetBlockTextureMapping(int textureIndex, BlockFaceDirection direction) { int y = textureIndex/BlockTextureAtlasSize; // y-position for the texture. int x = textureIndex%BlockTextureAtlasSize; // x-position for the texture. float yOffset = y*UnitBlockTextureOffset; // the unit y-offset. float xOffset = x*UnitBlockTextureOffset; // the unit x-offset; var mapping = new HalfVector2[6]; // contains texture mapping for the two triangles contained. switch (direction) { case BlockFaceDirection.XIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 // first triangle. mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 // second triangle. mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.XDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 break; case BlockFaceDirection.YIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[1] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.YDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.ZIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 break; case BlockFaceDirection.ZDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; } return mapping; }
private static bool ExportData(this BinaryWriter writer, string tagName, HalfVector2[] vectorArray) { WriteTag(writer, tagName); if (vectorArray == null) { writer.Write(0); return true; } writer.Write(vectorArray.Length); foreach (var vectorVal in vectorArray) { writer.Write(vectorVal.PackedValue); } return true; }
/// <summary> /// Read array of HalfVector2 /// </summary> private static HalfVector2[] ReadArrayOfHalfVector2(BinaryReader reader) { var nCount = reader.ReadInt32(); var vectorArray = new HalfVector2[nCount]; for (var i = 0; i < nCount; ++i) { vectorArray[i] = ReadHalfVector2(reader); } return vectorArray; }
public bool ExportDataPackedAsHV2(string tagName, Vector2[] vctArr) { WriteTag(tagName); if (vctArr == null) { m_writer.Write(0); return true; } m_writer.Write(vctArr.Length); foreach (Vector2 vctVal in vctArr) { HalfVector2 vct = new HalfVector2(vctVal); WriteVector(vct); } return true; }
/// <summary> /// Write HalfVector2 /// </summary> private static void WriteHalfVector2(this BinaryWriter writer, ref HalfVector2 value) { writer.Write(value.PackedValue); }
public bool ExportData(string tagName, HalfVector2[] vctArr) { WriteTag(tagName); if (vctArr == null) { m_writer.Write(0); return true; } m_writer.Write(vctArr.Length); foreach (HalfVector2 vctVal in vctArr) { WriteVector(vctVal); } return true; }
internal MyVertexFormatTexcoordNormalTangent(HalfVector2 texcoord, Vector3 normal, Vector4 tangent) { Texcoord = texcoord; Normal = VF_Packer.PackNormalB4(ref normal); Tangent = VF_Packer.PackTangentSignB4(ref tangent); }
/// <summary> /// Calculates uv-mampings for given texture and direction. /// </summary> /// <param name="textureIndex">The asked texture's texture-index.</param> /// <param name="direction">The asked direction.</param> /// <returns>Returns list of uv-mappings for given textureIndex and face-direction.</returns> private static HalfVector2[] GetBlockTextureMapping(int textureIndex, BlockFaceDirection direction) { int y = textureIndex / BlockTextureAtlasSize; // y-position for the texture. int x = textureIndex % BlockTextureAtlasSize; // x-position for the texture. float yOffset = y * UnitBlockTextureOffset; // the unit y-offset. float xOffset = x * UnitBlockTextureOffset; // the unit x-offset; var mapping = new HalfVector2[6]; // contains texture mapping for the two triangles contained. switch (direction) { case BlockFaceDirection.XIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 // first triangle. mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 // second triangle. mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.XDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 break; case BlockFaceDirection.YIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[1] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.YDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; case BlockFaceDirection.ZIncreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[3] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 mapping[5] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 break; case BlockFaceDirection.ZDecreasing: mapping[0] = new HalfVector2(xOffset, yOffset); // 0,0 mapping[1] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[2] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[3] = new HalfVector2(xOffset, yOffset + UnitBlockTextureOffset); // 0,1 mapping[4] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset); // 1,0 mapping[5] = new HalfVector2(xOffset + UnitBlockTextureOffset, yOffset + UnitBlockTextureOffset); // 1,1 break; } return(mapping); }
internal MyVertexFormatTexcoordNormalTangentTexindices(Vector2 texcoord, Vector3 normal, Vector3 tangent, Byte4 texIndices) { Texcoord = new HalfVector2(texcoord.X, texcoord.Y); Normal = VF_Packer.PackNormalB4(ref normal); Vector4 T = new Vector4(tangent, 1); Tangent = VF_Packer.PackTangentSignB4(ref T); TexIndices = texIndices; }
public void SendPlayerState() { PlayerStateChange stateChange = new PlayerStateChange(true, true, true); // Convert/Compress data values for optimal usage of bandwidth HalfVector2 position = new HalfVector2(m_player.Position); // Write the data to each player in the sesion Global.packetWriter.Write(stateChange.DataToBeSent); Global.packetWriter.Write(m_player.State.DirectionFlags); Global.packetWriter.Write(position.PackedValue); Global.packetWriter.Write((byte)m_player.Facing); m_player.Net.SendData(Global.packetWriter, SendDataOptions.InOrder); // Display what was sent in the GUI NetInfo info = new NetInfo(); info.direction = m_player.State.DirectionFlags; info.facing = m_player.Facing; info.position = m_player.Position; m_networkGUI.AddMessage("Sent: " + info); }
private static void AddVertex(Chunk chunk, Vector3Int position, Vector3 addition, HalfVector2 textureCoordinate, float sunlight, Color localLight) { chunk.VertexList.Add(new BlockVertex(position.AsVector3() + addition, textureCoordinate, sunlight)); //chunk.VertexList.Add(new BlockVertex(position.AsVector3() + addition, textureCoordinate, sunlight, localLight.ToVector3())); }
private void GetColorData(Texture2D texture2D) { int colorDataLength = texture2D.Width * texture2D.Height; colorData = new Color[colorDataLength]; switch (texture2D.Format) { case SurfaceFormat.Color: texture2D.GetData<Color>(colorData); break; case SurfaceFormat.Alpha8: var alpha8Data = new Alpha8[colorDataLength]; texture2D.GetData<Alpha8>(alpha8Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)alpha8Data[i]).ToVector4()); } break; case SurfaceFormat.Bgr565: var bgr565Data = new Bgr565[colorDataLength]; texture2D.GetData<Bgr565>(bgr565Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)bgr565Data[i]).ToVector4()); } break; case SurfaceFormat.Bgra4444: var bgra4444Data = new Bgra4444[colorDataLength]; texture2D.GetData<Bgra4444>(bgra4444Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)bgra4444Data[i]).ToVector4()); } break; case SurfaceFormat.Bgra5551: var bgra5551Data = new Bgra5551[colorDataLength]; texture2D.GetData<Bgra5551>(bgra5551Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)bgra5551Data[i]).ToVector4()); } break; case SurfaceFormat.HalfSingle: var halfSingleData = new HalfSingle[colorDataLength]; texture2D.GetData<HalfSingle>(halfSingleData); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)halfSingleData[i]).ToVector4()); } break; case SurfaceFormat.HalfVector2: var halfVector2Data = new HalfVector2[colorDataLength]; texture2D.GetData<HalfVector2>(halfVector2Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)halfVector2Data[i]).ToVector4()); } break; case SurfaceFormat.HalfVector4: var halfVector4Data = new HalfVector4[colorDataLength]; texture2D.GetData<HalfVector4>(halfVector4Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)halfVector4Data[i]).ToVector4()); } break; case SurfaceFormat.NormalizedByte2: var normalizedByte2Data = new NormalizedByte2[colorDataLength]; texture2D.GetData<NormalizedByte2>(normalizedByte2Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)normalizedByte2Data[i]).ToVector4()); } break; case SurfaceFormat.NormalizedByte4: var normalizedByte4Data = new NormalizedByte4[colorDataLength]; texture2D.GetData<NormalizedByte4>(normalizedByte4Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)normalizedByte4Data[i]).ToVector4()); } break; case SurfaceFormat.Rg32: var rg32Data = new Rg32[colorDataLength]; texture2D.GetData<Rg32>(rg32Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)rg32Data[i]).ToVector4()); } break; case SurfaceFormat.Rgba64: var rgba64Data = new Rgba64[colorDataLength]; texture2D.GetData<Rgba64>(rgba64Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)rgba64Data[i]).ToVector4()); } break; case SurfaceFormat.Rgba1010102: var rgba1010102Data = new Rgba1010102[colorDataLength]; texture2D.GetData<Rgba1010102>(rgba1010102Data); for (int i = 0; i < colorDataLength; i++) { colorData[i] = new Color(((IPackedVector)rgba1010102Data[i]).ToVector4()); } break; default: throw new Exception("Texture surface format not supported"); } }
public VertexPNCompressed(Vector3 position, Vector3 normal) { Position = position; Normal = new HalfVector2(MathUtils.CompressNormal(normal)); }
void ReadPlayerStates() { while (m_player.Net.IsDataAvailable) { // Get the new state for a remote player NetworkGamer sender; m_player.Net.ReceiveData(Global.packetReader, out sender); if (sender.IsLocal) continue; // Make sure that remote player's are activated for play after getting a packet from them Player remotePlayer = sender.Tag as Player; remotePlayer.Active = true; // Store the players current state, updating each value below if a change came over the network byte direction = remotePlayer.State.DirectionFlags; Vector2 position = remotePlayer.Position; FacingDirection facing = remotePlayer.State.Facing; // Update the remote player's state on this machine PlayerStateChange changes = new PlayerStateChange(Global.packetReader.ReadByte()); if (changes.DirectionChanged) direction = Global.packetReader.ReadByte(); if (changes.UpdatePosition) { HalfVector2 packedVector = new HalfVector2(); packedVector.PackedValue = Global.packetReader.ReadUInt32(); position = packedVector.ToVector2(); } if (changes.UpdateFacing) { facing = (FacingDirection)Global.packetReader.ReadByte(); } remotePlayer.State.DirectionFlags = direction; remotePlayer.Position = position; remotePlayer.Facing = facing; remotePlayer.Active = true; NetInfo netInfo = new NetInfo(); netInfo.direction = direction; netInfo.position = position; netInfo.facing = facing; m_networkGUI.AddMessage("Receiving: " + netInfo); } }