public static NwMaterial ToNwMaterial(Material m, string name, ref List <NwTexture2D> bitmaps, ref List <NwCubemap> cubemaps) { var mat = new NwMaterial(); mat.Name = name; foreach (var v in m.floatParams) { mat.Floats.Add(v.Key, v.Value.value); } foreach (var v in m.vec2Params) { mat.Vector2s.Add(v.Key, v.Value.value.ToVec2f()); } foreach (var v in m.vec3Params) { mat.Vector3s.Add(v.Key, v.Value.value.ToVec3f()); } foreach (var v in m.vec4Params) { mat.Vector4s.Add(v.Key, v.Value.value.ToVec4f()); } foreach (var v in m.colorParams) { mat.Color4s.Add(v.Key, v.Value.value.ToColor4f()); } foreach (var v in m.mat4Params) { mat.Matrix4s.Add(v.Key, v.Value.value.ToMat4f()); } foreach (var v in m.tex2DParams) { if (v.Value.value != null) { var bm = ToNwTexture2D(v.Value.value.SrcBitmap, null); if (!bitmaps.Exists(b => b.Hash == bm.Hash)) { bitmaps.Add(bm); } mat.Texture2Ds.Add(v.Key, bm.Hash); } else { mat.Texture2Ds.Add(v.Key, null); } } return(mat); }
public static Material FromNwMaterial(NwMaterial mat, ref NwTexture2D[] texs, ref Texture2D[] texs2) { var m = new Material(); foreach (var v in mat.Floats) { m.AddParam(v.Key, v.Value); } foreach (var v in mat.Vector2s) { m.AddParam(v.Key, v.Value.FromVec2f()); } foreach (var v in mat.Vector3s) { m.AddParam(v.Key, v.Value.FromVec3f()); } foreach (var v in mat.Vector4s) { m.AddParam(v.Key, v.Value.FromVec4f()); } foreach (var v in mat.Color4s) { m.AddParam(v.Key, v.Value.FromColor4f()); } foreach (var v in mat.Matrix4s) { m.AddParam(v.Key, v.Value.FromMat4f()); } foreach (var v in mat.Texture2Ds) { var idx = Array.FindIndex(texs, t => t.Hash == v.Value); if (idx != -1) { m.AddParam(v.Key, texs2[idx]); } else { m.AddParam <Texture2D>(v.Key, null); } } return(m); }