Browse Source

First setup to upload brush models (specifically: the world model) from Quake to Unity. Updated the QWorld class to include the fields added by QuakeSpasm.

console
Nico de Poel 5 years ago
parent
commit
96d2a1fe7b
  1. 13
      Assets/Scripts/Data/QModel.cs
  2. 11
      Assets/Scripts/Modules/RenderModule.Interop.cs
  3. 9
      Assets/Scripts/Modules/RenderModule.cs
  4. 1
      engine/Quake/gl_model.h
  5. 2
      engine/Quake/gl_rmisc.c
  6. 6
      engine/UniQuake/gl_uniquake.c

13
Assets/Scripts/Data/QModel.cs

@ -13,6 +13,7 @@ public class QModel
private const int MaxMapHulls = 4; // Should correspond to MAX_MAP_HULLS private const int MaxMapHulls = 4; // Should correspond to MAX_MAP_HULLS
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MaxPath)] public string name; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MaxPath)] public string name;
public uint pathId;
public bool needLoad; public bool needLoad;
public QModelType type; public QModelType type;
@ -23,7 +24,8 @@ public class QModel
// Volume occupied by the model graphics // Volume occupied by the model graphics
public QVec3 mins, maxs; public QVec3 mins, maxs;
public float radius;
public QVec3 ymins, ymaxs;
public QVec3 rmins, rmaxs;
// Solid volume for clipping // Solid volume for clipping
public bool clipBox; public bool clipBox;
@ -74,6 +76,15 @@ public class QModel
public IntPtr lightData; // Array of bytes public IntPtr lightData; // Array of bytes
[MarshalAs(UnmanagedType.LPStr)] public string entities; [MarshalAs(UnmanagedType.LPStr)] public string entities;
public bool visWarn;
public int bspVersion;
public uint meshvbo;
public uint meshIndexesVbo;
public int vboIndexOfs;
public int vboXyzOfs;
public int vboStofs;
public IntPtr userCache; public IntPtr userCache;
} }

11
Assets/Scripts/Modules/RenderModule.Interop.cs

@ -14,6 +14,7 @@ public partial class RenderModule: CallbackHandler<RenderModule>
target = TargetPtr, target = TargetPtr,
UploadAliasModel = CreateCallback<UploadAliasModelCallback>(Callback_UploadAliasModel), UploadAliasModel = CreateCallback<UploadAliasModelCallback>(Callback_UploadAliasModel),
UploadBrushModel = CreateCallback<UploadBrushModelCallback>(Callback_UploadBrushModel),
}; };
RegisterCallbacks(callbacks); RegisterCallbacks(callbacks);
@ -28,6 +29,7 @@ public partial class RenderModule: CallbackHandler<RenderModule>
public IntPtr target; public IntPtr target;
public IntPtr UploadAliasModel; public IntPtr UploadAliasModel;
public IntPtr UploadBrushModel;
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
@ -63,4 +65,13 @@ public partial class RenderModule: CallbackHandler<RenderModule>
triangles.ToStructArray<QTriangle>(header.numTriangles), triangles.ToStructArray<QTriangle>(header.numTriangles),
stVerts.ToStructArray<QSTVert>(header.numVerts)); stVerts.ToStructArray<QSTVert>(header.numVerts));
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int UploadBrushModelCallback(IntPtr target, QModel model);
[MonoPInvokeCallback(typeof(UploadBrushModelCallback))]
private static int Callback_UploadBrushModel(IntPtr target, QModel model)
{
return GetSelf(target).UploadBrushModel(model);
}
} }

9
Assets/Scripts/Modules/RenderModule.cs

@ -70,4 +70,13 @@ public partial class RenderModule
xPos += 0.5f; xPos += 0.5f;
return 1; return 1;
} }
private int UploadBrushModel(QModel model)
{
if (model.type != QModelType.Brush)
return -1;
Debug.Log($"Brush model '{model.name}' with {model.numLeafs} leafs, {model.numVertices} vertices, {model.numSurfaces} surfaces");
return 1;
}
} }

1
engine/Quake/gl_model.h

@ -517,5 +517,6 @@ byte *Mod_NoVisPVS (qmodel_t *model);
void Mod_SetExtraFlags (qmodel_t *mod); void Mod_SetExtraFlags (qmodel_t *mod);
int UQ_GL_UploadAliasModel(qmodel_t *model, aliashdr_t *aliashdr, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts); int UQ_GL_UploadAliasModel(qmodel_t *model, aliashdr_t *aliashdr, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts);
int UQ_GL_UploadBrushModel(qmodel_t *model);
#endif // __MODEL__ #endif // __MODEL__

2
engine/Quake/gl_rmisc.c

@ -401,6 +401,8 @@ void R_NewMap (void)
GL_BuildBModelVertexBuffer (); GL_BuildBModelVertexBuffer ();
//ericw -- no longer load alias models into a VBO here, it's done in Mod_LoadAliasModel //ericw -- no longer load alias models into a VBO here, it's done in Mod_LoadAliasModel
UQ_GL_UploadBrushModel(cl.worldmodel);
r_framecount = 0; //johnfitz -- paranoid? r_framecount = 0; //johnfitz -- paranoid?
r_visframecount = 0; //johnfitz -- paranoid? r_visframecount = 0; //johnfitz -- paranoid?

6
engine/UniQuake/gl_uniquake.c

@ -11,6 +11,7 @@ typedef struct unity_glcalls_s
void *target; void *target;
int(*UploadAliasModel)(void *target, const char *name, aliashdr_t *aliashdr, maliasframedesc_t *frames, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts); int(*UploadAliasModel)(void *target, const char *name, aliashdr_t *aliashdr, maliasframedesc_t *frames, trivertx_t **poseVerts, mtriangle_t *triangles, stvert_t *stVerts);
int(*UploadBrushModel)(void *target, qmodel_t *model);
} unity_glcalls_t; } unity_glcalls_t;
const unity_glcalls_t *unity_glcalls; const unity_glcalls_t *unity_glcalls;
@ -21,3 +22,8 @@ int UQ_GL_UploadAliasModel(qmodel_t *model, aliashdr_t *aliashdr, trivertx_t **p
// so we pass along the pointer to the first frame struct which allows us to manually marshal the entire array. // so we pass along the pointer to the first frame struct which allows us to manually marshal the entire array.
return unity_glcalls->UploadAliasModel(unity_glcalls->target, model->name, aliashdr, &aliashdr->frames[0], poseVerts, triangles, stVerts); return unity_glcalls->UploadAliasModel(unity_glcalls->target, model->name, aliashdr, &aliashdr->frames[0], poseVerts, triangles, stVerts);
} }
int UQ_GL_UploadBrushModel(qmodel_t *model)
{
return unity_glcalls->UploadBrushModel(unity_glcalls->target, model);
}
Loading…
Cancel
Save