private void ParseMatrixAndVector() { R2ROMLoader l = MapLoader.Loader as R2ROMLoader; LevelHeader lh = l.Get <LevelHeader>((ushort)(l.CurrentLevel | (ushort)FATEntry.Flag.Fix)); if (lh != null) { Short3Array indices = lh.indices.Value; Vector3Array vectors = lh.vectors.Value; matrix = ROMTransform.ROMMatrix.Get(matrixIndex, indices, vectors); if (vectorIndex != 0xFFFF && vectorIndex < vectors.length) { vector = vectors.vectors[vectorIndex]; } } }
public ROMTransform(ushort index) { if (index == 0xFFFF) { return; } R2ROMLoader l = MapLoader.Loader as R2ROMLoader; LevelHeader lh = l.Get <LevelHeader>((ushort)(l.CurrentLevel | (ushort)FATEntry.Flag.Fix)); if (lh != null) { Short3Array indices = lh.indices.Value; Vector3Array vectors = lh.vectors.Value; Short3Array.Triangle tri = lh.indices.Value.triangles[index]; rotationMatrix = ROMMatrix.Get(tri.v1, indices, vectors); scaleMatrix = ROMMatrix.Get(tri.v2, indices, vectors); if (tri.v3 != 0xFFFF && tri.v3 < vectors.length) { //MapLoader.Loader.print(tri.v3); position = vectors.vectors[tri.v3]; //MapLoader.Loader.print(transform.position); } } }
private void UpdateBackgroundROM() { // Update background color or material Color?backgroundColor = null; OpenSpace.ROM.VisualMaterial skyMaterial = null; OpenSpace.ROM.VisualMaterial[] skyMaterialsDD = null; SectorComponent activeBackgroundSector = null; OpenSpace.Loader.R2ROMLoader l = MapLoader.Loader as OpenSpace.Loader.R2ROMLoader; OpenSpace.ROM.LevelHeader lh = l.level; if (lh != null && lh.backgroundUpLeft != null && lh.backgroundUpLeft.Value != null && lh.backgroundUpRight != null && lh.backgroundUpRight.Value != null && lh.backgroundDownLeft != null && lh.backgroundDownLeft.Value != null && lh.backgroundDownRight != null && lh.backgroundDownRight.Value != null) { skyMaterial = null; skyMaterialsDD = new OpenSpace.ROM.VisualMaterial[4]; skyMaterialsDD[0] = lh.backgroundUpLeft.Value; skyMaterialsDD[1] = lh.backgroundUpRight.Value; skyMaterialsDD[2] = lh.backgroundDownLeft.Value; skyMaterialsDD[3] = lh.backgroundDownRight.Value; } else { if (sectorManager != null && sectorManager.sectors != null && sectorManager.sectors.Count > 0) { foreach (SectorComponent s in sectorManager.sectors) { if (!s.Loaded) { continue; } if (s.sectorROM == null) { continue; } if (s.sectorROM.background != null && s.sectorROM.background.Value != null && s.sectorROM.background.Value.num_textures > 0 && s.sectorROM.background.Value.textures.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value != null && s.sectorROM.background.Value.textures.Value.vmTex[0].texRef.Value.texInfo.Value != null) { skyMaterial = s.sectorROM.background; //print(skyMaterial.Offset); activeBackgroundSector = s; break; } else { /*foreach (LightInfo li in s.sector.staticLights) { * if (li.type == 6) { * backgroundColor = li.background_color; * break; * } * }*/ } } } } if (!controller.viewCollision) { if (skyMaterial != null) { backgroundPanel.gameObject.SetActive(true); if (backgroundMaterialROM != skyMaterial) { backgroundMaterialROM = skyMaterial; Material skyboxMat = skyMaterial.GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); /*Texture tex = skyboxMat.GetTexture("_Tex0"); * tex.filterMode = FilterMode.Point; * tex.wrapMode = TextureWrapMode.Clamp; * skyboxMat.SetTexture("_Tex0", tex);*/ backgroundPanel.sharedMaterial = skyboxMat; } //skyboxMat.SetFloat("_DisableLighting", 1f); backgroundPanel.sharedMaterial.SetFloat("_DisableLightingLocal", 1f); if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { backgroundPanel.gameObject.SetActive(false); } if (skyMaterialsDD != null) { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(true); } if (backgroundMaterialsDDROM == null) { backgroundMaterialsDDROM = skyMaterialsDD; for (int i = 0; i < 4; i++) { Material skyboxMat = skyMaterialsDD[i].GetMaterial(OpenSpace.ROM.VisualMaterial.Hint.None); backgroundPanelsROM[i].sharedMaterial = skyboxMat; backgroundPanelsROM[i].sharedMaterial.SetFloat("_DisableLightingLocal", 1f); } } if (activeBackgroundSector != null) { if (activeBackgroundSector != previousActiveBackgroundSector) { //backgroundPanel.material.SetFloat("_DisableLightingLocal", 0f); //sectorManager.ApplySectorLighting(activeBackgroundSector, backgroundPanel.gameObject, LightInfo.ObjectLightedFlag.Environment); previousActiveBackgroundSector = activeBackgroundSector; } } else { //backgroundPanel.material.SetFloat("_DisableLighting", 1f); } //RenderSettings.skybox = skyboxMat; //Camera.main.clearFlags = CameraClearFlags.Skybox; } else { for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } } } else { backgroundPanel.gameObject.SetActive(false); for (int i = 0; i < 4; i++) { backgroundPanelsROM[i].gameObject.SetActive(false); } //RenderSettings.skybox = null; //Camera.main.clearFlags = CameraClearFlags.SolidColor; } if (backgroundColor.HasValue && !controller.viewCollision) { Camera.main.backgroundColor = backgroundColor.Value; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, backgroundColor.Value, 0.5f * Time.deltaTime); } else { Camera.main.backgroundColor = Color.black; //Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, Color.black, 0.5f * Time.deltaTime); } }