internal static void Instantiate(Round2.Generated.Binary.OBOA.Package proto) { RTOBOA l_obj = GameObject.CreatePrimitive(PrimitiveType.Plane).AddComponent <RTOBOA>(); Destroy(l_obj.collider); l_obj.m_proto = proto; l_obj.transform.position = new Vector3(-proto.m_x_pos_20, proto.m_y_pos_24, proto.m_z_pos_28); l_obj.transform.rotation = new Quaternion(proto.m_x_pos_20, proto.m_y_rot_30, proto.m_z_rot_34, proto.m_w_rot_38); if (proto.m_M3GA_link_0.m_lnkId != 0) { Round2.Generated.Binary.M3GM l_m3gm = proto.m_M3GA_link_0.Value.m_pkg_20[0].m_M3GM_link_0.Value; l_obj.GetComponent <MeshFilter>().mesh = l_m3gm.UnityMesh; l_obj.gameObject.AddComponent <MeshCollider>().mesh = l_m3gm.UnityMesh; l_obj.renderer.material.mainTexture = l_m3gm.m_TXMP_link_24.Value.Surface_0; } if (proto.m_door_id_14 > 0) { int l_realdID = proto.m_door_id_14 & 0x0FFF; if (!m_doorIDLST.ContainsKey(l_realdID)) { m_doorIDLST.Add(l_realdID, new List <RTOBOA>()); } m_doorIDLST[l_realdID].Add(l_obj); } l_obj.gameObject.SetActive(false); }
void OnInitialize() { try { transform.position = new Vector3(-m_proto.m_header.m_pos.x, m_proto.m_header.m_pos.y, m_proto.m_header.m_pos.z); foreach (RTOBOA obj in m_myOBJS = RTOBOA.GetByDoorID((int)m_proto.m_doorID & 0x0FFF)) { Round2.Generated.Binary.OBOA.Package l_pkg = obj.m_proto; m_rotations.Add(m_proto.m_header.m_rot); gameObject.name = m_proto.m_doorType + "::" + m_proto.m_doorID + "(" + m_proto.m_keyID + ")"; Round2.Generated.Binary.DOOR l_doorClass = Round2.Generated.Binary.DOOR.PendDoorClass(m_proto.m_doorType); obj.SetOBANInput(l_doorClass.m_OBAN_link_10.Value); if (l_pkg != null) { Round2.Generated.Binary.OBAN.Package l_frame0 = l_doorClass.m_OBAN_link_10.Value.m_pkg_80[0]; Vector3 l_rot = new Oni.Quaternion(l_frame0.m_x_rot_0, l_frame0.m_y_rot_4, l_frame0.m_z_rot_8, l_frame0.m_w_rot_C).UnityQuaternionRaw().eulerAngles; m_rotations.Add(l_rot); obj.transform.position = new Vector3(-l_pkg.m_x_pos_20, l_pkg.m_y_pos_24, l_pkg.m_z_pos_28); Oni.Vector3 l_scale; Oni.Vector3 l_pos; Oni.Quaternion l__rot; m_rotations.Add(l__rot.UnityQuaternionRaw().eulerAngles); l_doorClass.m_OBAN_link_10.Value.InitialTransform.Decompose(out l_scale, out l__rot, out l_pos); //more looks like a hack. Still works fine. obj.transform.rotation = Quaternion.Euler(m_rotations[0]) * Quaternion.Euler(m_rotations[1]) * Quaternion.Euler(180, 0, 0); } GameObject l_pivot = new GameObject("pivot"); l_pivot.transform.parent = transform; l_pivot.transform.position = obj.transform.position; l_pivot.transform.rotation = obj.transform.rotation; obj.transform.parent = l_pivot.transform; if (obj.m_proto.m_door_id_14 > 0 && ((int)obj.m_proto.m_door_id_14 & 0x1000) != 0) { //l_pivot.name += " # mirror "; l_pivot.transform.rotation *= Quaternion.Euler(180, 180, 0); } obj.gameObject.SetActive(true); } SphereCollider l_sc = gameObject.AddComponent <SphereCollider>(); l_sc.radius = Mathf.Sqrt(m_proto.m_activationRadius) / 2f; l_sc.center = Vector3.up * (l_sc.radius); l_sc.isTrigger = true; } catch (System.Exception ee) { Debug.LogException(ee, this); } }
public void Build() { //m_bldr = new GeometryBuilder(this.m_Level_name_8, this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array, this.m_AKEV_Link_48.Value.m_TXCA_link_10.Value.Array); l_lvlObj = new GameObject(this.m_Level_name_8); l_lvlObj.AddComponent <MeshRenderer>().material = new Material(Shader.Find("VertexShadedDiffuse")); foreach (AGQR.Package renderInfo in this.m_AKEV_Link_48.Value.m_AGQR_link_18.Value.m_pkg_20) { if (!m_fullRenderInfo.ContainsKey(renderInfo.m_TXMA_id_0)) { m_fullRenderInfo.Add(renderInfo.m_TXMA_id_0, new Dictionary <int, GeometryBuilder>()); } } HashSet <int> l_ignoreQuadLst = new HashSet <int>(); /* * foreach (OBOA.Package pkg in this.m_OBOA_Link_4C.Value.m_pkg_20) * { * OBJCInst.BindOBOAPKG(pkg); * }*/ foreach (ONOA.Package pkg in this.m_ONOA_Link_74.Value.m_pkg_20) { if (pkg.m_High_bit_3 == 0x03)//let's search only for doors { if (pkg.m_IDXA_link_4.m_lnkId != 0) { foreach (IDXA.Package index in pkg.m_IDXA_link_4.Value.m_pkg_20) { l_ignoreQuadLst.Add(index.m_Index_id_0); } } else { Debug.LogError("IDXA LINK = 0"); } } } int l_i = 0; foreach (OBOA.Package pkg in this.m_OBOA_Link_4C.Value.m_pkg_20) { l_i++; RTOBOA.Instantiate(pkg); //Door.OBOALink(pkg); if (pkg.m_OBAN_link_4.m_lnkId != 0) { /* * TODO : implement OBOA's not only for doors, similar to code below: * string l_objname = pkg.m_Name_70; * UnityEngine.Vector3 l_pos = new UnityEngine.Vector3(-pkg.m_OBAN_link_4.Value.m_x_position_3C, pkg.m_OBAN_link_4.Value.m_y_position_40, pkg.m_OBAN_link_4.Value.m_z_position_44); * GameObject l_g = new GameObject(l_objname); * l_g.transform.position = l_pos; * l_g.AddComponent<MeshRenderer>().material = new Material(Shader.Find("Diffuse")); * l_g.AddComponent<MeshFilter>().mesh = pkg.m_M3GA_link_0.Value.m_pkg_20[0].m_M3GM_link_0.Value.UnityMesh; * l_g.AddComponent<MeshCollider>().mesh = pkg.m_M3GA_link_0.Value.m_pkg_20[0].m_M3GM_link_0.Value.UnityMesh; * l_g.transform.position = new UnityEngine.Vector3(-pkg.m_OBAN_link_4.Value.m_x_position_3C, pkg.m_OBAN_link_4.Value.m_y_position_40, pkg.m_OBAN_link_4.Value.m_z_position_44);*/ } else { Debug.LogError("OBAN LINK = 0, " + l_i + "\\" + this.m_OBOA_Link_4C.Value.m_pkg_20.Length); } } List <int> .Enumerator l_renderKeysEnumerator = new List <int>(this.m_AKEV_Link_48.Value.m_AGQR_link_18.Value.m_pkg_20.ConvertAll <AGQR.Package, int>(u => u.m_TXMA_id_0)).GetEnumerator(); int l_quadID = 0; foreach (AGQG.Package quad in this.m_AKEV_Link_48.Value.m_AGQG_link_14.Value.m_pkg_20) { l_renderKeysEnumerator.MoveNext(); if (!m_fullRenderInfo[l_renderKeysEnumerator.Current].ContainsKey(quad.m_flags_30)) { TXMP l_tx = this.m_AKEV_Link_48.Value.m_TXMA_link_24.Value.m_pkg_20[l_renderKeysEnumerator.Current].m_TXMP_link_0.Value; m_fullRenderInfo[l_renderKeysEnumerator.Current].Add(quad.m_flags_30, new GeometryBuilder(l_tx == null ? "unknown texture" : l_tx.m_FileName_8, this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array, this.m_AKEV_Link_48.Value.m_TXCA_link_10.Value.Array)); } if (!l_ignoreQuadLst.Contains(l_quadID++))//i bet nobody needs additional vertices for doors { //Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_1_0], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_2_4], Color.green, 15f); //Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_2_4], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_3_8], Color.green, 15f); { if (quad.m_pnta_id_3_8 == quad.m_pnta_id_4_C) { byte[] l_color1Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_1_20); byte[] l_color2Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_2_24); byte[] l_color3Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_3_28); m_fullRenderInfo[l_renderKeysEnumerator.Current][quad.m_flags_30] .Triangle ( quad.m_pnta_id_1_0, quad.m_pnta_id_2_4, quad.m_pnta_id_3_8, quad.m_txca_id_1_10, quad.m_txca_id_2_14, quad.m_txca_id_3_18, new Color32[] { new Color32(l_color1Bytes[2], l_color1Bytes[1], l_color1Bytes[0], l_color1Bytes[3]), new Color32(l_color2Bytes[2], l_color2Bytes[1], l_color2Bytes[0], l_color2Bytes[3]), new Color32(l_color3Bytes[2], l_color3Bytes[1], l_color3Bytes[0], l_color3Bytes[3]) } ); Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_3_8], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_3_8] + UnityEngine.Vector3.up, new Color32(l_color1Bytes[0], l_color1Bytes[1], l_color1Bytes[2], l_color1Bytes[3]), 15f); //m_bldr.Triangle(quad.m_pnta_id_1_0, quad.m_pnta_id_2_4, quad.m_pnta_id_3_8, quad.m_txca_id_1_10, quad.m_txca_id_2_14, quad.m_txca_id_3_18); //Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_3_8], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_1_0], Color.green, 15f); } else { byte[] l_color1Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_1_20); byte[] l_color2Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_2_24); byte[] l_color3Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_3_28); byte[] l_color4Bytes = System.BitConverter.GetBytes(quad.m_argb_vrtx_color_4_2C); m_fullRenderInfo[l_renderKeysEnumerator.Current][quad.m_flags_30] .Quad ( quad.m_pnta_id_1_0, quad.m_pnta_id_2_4, quad.m_pnta_id_3_8, quad.m_pnta_id_4_C, quad.m_txca_id_1_10, quad.m_txca_id_2_14, quad.m_txca_id_3_18, quad.m_txca_id_4_1C, new Color32[] { new Color32(l_color1Bytes[2], l_color1Bytes[1], l_color1Bytes[0], l_color1Bytes[3]), new Color32(l_color2Bytes[2], l_color2Bytes[1], l_color2Bytes[0], l_color2Bytes[3]), new Color32(l_color3Bytes[2], l_color3Bytes[1], l_color3Bytes[0], l_color3Bytes[3]), new Color32(l_color4Bytes[2], l_color4Bytes[1], l_color4Bytes[0], l_color4Bytes[3]) } ); //m_bldr.Quad(quad.m_pnta_id_1_0, quad.m_pnta_id_2_4, quad.m_pnta_id_3_8, quad.m_pnta_id_4_C, quad.m_txca_id_1_10, quad.m_txca_id_2_14, quad.m_txca_id_3_18, quad.m_txca_id_4_1C); //Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_3_8], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_4_C], Color.green, 15f); //Debug.DrawLine(this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_4_C], this.m_AKEV_Link_48.Value.m_PNTA_link_8.Value.Array[quad.m_pnta_id_1_0], Color.green, 15f); } } } } if (this.m_ENVP_Link_78.m_lnkId != 0) { foreach (ENVP.Package particle in this.m_ENVP_Link_78.Value.m_pkg_20) { Oni.Matrix l_trs = new Oni.Matrix ( particle.m_transform_a11_70, particle.m_transform_a12_74, particle.m_transform_a13_78, 0, particle.m_transform_a21_7C, particle.m_transform_a22_80, particle.m_transform_a23_84, 0, particle.m_transform_a31_88, particle.m_transform_a32_8C, particle.m_transform_a33_90, 0, particle.m_transform_a41_94, particle.m_transform_a42_98, particle.m_transform_a43_9C, 1 ); Oni.Vector3 l_scale; Oni.Vector3 l_pos; Oni.Quaternion l_rot; l_trs.Decompose(out l_scale, out l_rot, out l_pos); //Debug.DrawLine(UnityEngine.Vector3.zero, new UnityEngine.Vector3(-l_pos.X, l_pos.Y, l_pos.Z), Color.blue, 20f); //Debug.Log("#" + particle.m_3D_particle_0); //Debug.Log("$" + particle.m_Particle_name_40); } } foreach (int txid in m_fullRenderInfo.Keys) { foreach (int flags in m_fullRenderInfo[txid].Keys) { m_fullRenderInfo[txid][flags].UpdateMesh(); GameObject l_g = new GameObject(" flags = " + flags.ToString("X") + " :: " + m_fullRenderInfo[txid][flags].Name); Material l_m = (l_g.AddComponent <MeshRenderer>().material = new Material(Shader.Find("VertexShadedDiffuse"))); if (this.m_AKEV_Link_48.Value.m_TXMA_link_24.Value.m_pkg_20[txid] != null && this.m_AKEV_Link_48.Value.m_TXMA_link_24.Value.m_pkg_20[txid].m_TXMP_link_0.Value != null) { l_m.mainTexture = this.m_AKEV_Link_48.Value.m_TXMA_link_24.Value.m_pkg_20[txid].m_TXMP_link_0.Value.Surface_0; } l_g.AddComponent <MeshFilter>().mesh = m_fullRenderInfo[txid][flags].Mesh; GunkFlags l_quadFlags = (GunkFlags)flags; if ((l_quadFlags & GunkFlags.Ghost) != 0 || (l_quadFlags & GunkFlags.StairsUp) != 0 || (l_quadFlags & GunkFlags.StairsDown) != 0 || (l_quadFlags & GunkFlags.DoorFrame) != 0 || (l_quadFlags & GunkFlags.Furniture) != 0) { continue; } else { l_g.AddComponent <MeshCollider>().mesh = m_fullRenderInfo[txid][flags].Mesh; } } } //this.m_bldr.UpdateMesh(); //l_lvlObj.AddComponent<MeshFilter>().mesh = this.m_bldr.Mesh; }