You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.5 KiB
105 lines
3.5 KiB
using System.Collections.Generic;
|
|
using Unity.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
public partial class RenderModule
|
|
{
|
|
private readonly UniQuake uq;
|
|
|
|
public RenderModule(UniQuake uniQuake)
|
|
{
|
|
uq = uniQuake;
|
|
BuildCallbacks();
|
|
}
|
|
|
|
private int UploadAliasModel(string name, QAliasHeader header, QAliasFrameType frameType,
|
|
QTriVertex[][] poseVertices, QTriangle[] triangles, QSTVert[] stVertices,
|
|
QGLTexture[][] glTextures, QGLTexture[][] fbTextures)
|
|
{
|
|
Debug.Log($"Alias model '{name}' (frame type {frameType}) with {header.numVerts} vertices, {header.numTriangles} triangles, {header.numFrames} frame(s), {header.numPoses} pose(s)");
|
|
|
|
AliasModel aliasModel = new AliasModel(name, header, frameType);
|
|
aliasModel.ImportMeshData(poseVertices, triangles, stVertices);
|
|
aliasModel.Textures.Import(uq.GameAssets, glTextures, fbTextures);
|
|
|
|
uq.GameAssets.AddAliasModel(aliasModel);
|
|
|
|
return 1;
|
|
}
|
|
|
|
private int UploadBrushModel(QModel model)
|
|
{
|
|
Debug.Log($"Brush model '{model.name}' with {model.numVertices} vertices, {model.numEdges} edges, {model.numSurfaces} surfaces");
|
|
|
|
var brushModel = new BrushModel(model.name);
|
|
brushModel.ImportMeshData(model);
|
|
|
|
uq.GameAssets.AddBrushModel(brushModel);
|
|
|
|
return 1;
|
|
}
|
|
|
|
private int UploadWorldModel(QModel model)
|
|
{
|
|
Debug.Log($"World model '{model.name}' with {model.numVertices} vertices, {model.numEdges} edges, {model.numSurfaces} surfaces");
|
|
|
|
var worldModel = new BrushModel(model.name);
|
|
worldModel.ImportMeshData(model);
|
|
|
|
uq.GameAssets.SetWorldModel(worldModel);
|
|
uq.GameState.NewMap(worldModel);
|
|
|
|
return 1;
|
|
}
|
|
|
|
private bool UploadTexture(QGLTexture texture, byte[] data, ref uint texNum)
|
|
{
|
|
Debug.Log($"Texture '{texture.name}' with dimensions {texture.width}x{texture.height}, data size = {data.Length} bytes");
|
|
|
|
if (texture.width == 0 || texture.height == 0)
|
|
return false;
|
|
|
|
var tex = new Texture2D((int)texture.width, (int)texture.height, TextureFormat.RGBA32, texture.flags.HasFlag(QTexPrefs.Mipmap));
|
|
tex.name = texture.name;
|
|
tex.SetPixelData(data, 0);
|
|
tex.Apply();
|
|
|
|
texNum = uq.GameAssets.SetTexture(texNum, tex);
|
|
return true;
|
|
}
|
|
|
|
private bool UploadLightmap(int lightmapNum, int width, int height, byte[] data)
|
|
{
|
|
if (width == 0 || height == 0)
|
|
return false;
|
|
|
|
uq.GameAssets.UploadLightmap(lightmapNum, width, height, data);
|
|
return true;
|
|
}
|
|
|
|
private bool UploadLightmap(int lightmapNum, int width, int height, NativeArray<byte> data)
|
|
{
|
|
if (width == 0 || height == 0)
|
|
return false;
|
|
|
|
uq.GameAssets.UploadLightmap(lightmapNum, width, height, data);
|
|
return true;
|
|
}
|
|
|
|
private void SetupView(QVec3 origin, QVec3 angles, QLeaf viewLeaf)
|
|
{
|
|
var cam = uq.Camera;
|
|
if (cam == null)
|
|
return;
|
|
|
|
// Don't know exactly why this correction is necessary.
|
|
// Mixing Quake and Unity's coordinate systems creates a bit of a mess. With the current set of conversions
|
|
// we at least get everything to look right in every case I've tested, but it still seems a bit off somehow.
|
|
angles.y += 180;
|
|
angles.z = -angles.z;
|
|
|
|
cam.transform.position = origin.ToUnityPosition();
|
|
cam.transform.rotation = angles.ToUnityRotation();
|
|
}
|
|
}
|