DarkPlacesEngine / DarkPlaces

The DarkPlaces Quake engine, created by LadyHavoc. Official Git repository (replaces SVN).
https://icculus.org/twilight/darkplaces/
GNU General Public License v2.0
290 stars 42 forks source link

OBJ Support For MD3 Tags For Attachment Tutorial #181

Open Baker7 opened 5 months ago

Baker7 commented 5 months ago

Tutorial for OBJ supporting MD3 Tags For Attachment

Step 1: Open model_brush.c Step 2: Copy the following code and press CTRL-V in appropriate place in Mod_OBJ_Load(model_t mod, void buffer, void *bufferend) Step 3: Declare the int idx I didn't mention Step 4:

helicopter20

        // Baker: modification "tagname"
        else if (String_Match(argv[0], "tagname")) {
        // tagname propellor_topz -50.2 0.0 26.8
        // tagname propellor_rear 102.8 0.7 20.6
            loadmodel->num_tagframes = 1; // loadmodel->numframes; // Just 1 right?
            idx = loadmodel->num_tags ++;
            loadmodel->data_tags = 
                (aliastag_t *)Mem_Realloc(loadmodel->mempool, loadmodel->data_tags, 
                    loadmodel->num_tagframes * loadmodel->num_tags * sizeof(aliastag_t));

            c_strlcpy (loadmodel->data_tags[idx].name, argv[1]);

            loadmodel->data_tags[idx].matrixgl[9] = atof(argv[2]);
            loadmodel->data_tags[idx].matrixgl[10] = atof(argv[3]);
            loadmodel->data_tags[idx].matrixgl[11] = atof(argv[4]);

            // Baker: Throw an identity matrix in there for now, is this right?
            loadmodel->data_tags[idx].matrixgl[0] = 1;
            loadmodel->data_tags[idx].matrixgl[1] = 0;
            loadmodel->data_tags[idx].matrixgl[2] = 0;

            loadmodel->data_tags[idx].matrixgl[3] = 0;
            loadmodel->data_tags[idx].matrixgl[4] = 1;
            loadmodel->data_tags[idx].matrixgl[5] = 0;

            loadmodel->data_tags[idx].matrixgl[6] = 0;
            loadmodel->data_tags[idx].matrixgl[7] = 0;
            loadmodel->data_tags[idx].matrixgl[8] = 1;

OBJS: The main one is helicopter_less_2.obj which uses "tagname propellor_rear 102.8 0.7 20.6" to indicate attachment point.

helicopter.zip

In QuakeC you have do something like:

    entity xt = spawn();    
    setattachment (xt, self, "propellor_topz");
    xt.model = "models/vehicles/helicopter_propellor.obj";

Eventually I'll do a little QuakeC demo with the model.

hemebond commented 2 months ago

@Baker7 Does one add the tagname lines manually to the .obj file or is it already supported by the editor/exporter?

Baker7 commented 2 months ago

@Baker7 Does one add the tagname lines manually to the .obj file or is it already supported by the editor/exporter?

Manually. OBJ files are text files.

Note: To self, release something with that helicopter in it so a working example is out in the real world.

Might add -- I have .mdl with attachments also ... you pick a specific triangle of the model and can make it an attachment point ... when the .mdl is loaded, the attachment data is generated for indicated triangles.

backpack_attachment

qmeselecttriangle

qmeselecttriangle1

Baker7 commented 6 days ago

Hemebond ...

Here is a test case for you ...

helicopter_map2

Download Link: https://www.moddb.com/mods/zircon-engine/downloads/the-helicopter-map

Helicopter lives in models/vehicles/helicopter.obj

QC ... qc/extras/misc_mdl_entity.c

hemebond commented 6 days ago

Might add -- I have .mdl with attachments also ... you pick a specific triangle of the model and can make it an attachment point ... when the .mdl is loaded, the attachment data is generated for indicated triangles.

Is this a separate change from what you shared in the first comment?

Baker7 commented 6 days ago

.mdl md3tags is a separate change and was quite a huge amount of work (has to pre-compute triangle rotation at model load time for every morphframe). .mdl md3tags was implemented in Zircon Beta #59 and Zircon Beta #58 didn't have it, so using WinMerge or your favorite open source diff application to compare the 2 folders shows the changes pretty clearly.

58 is https://www.moddb.com/mods/zircon-engine/downloads/zircon-beta-release-58-win64-binary-source

59 is https://www.moddb.com/mods/zircon-engine/downloads/zircon-beta-release-59-win64-linux-binaries-source

But the payoff is making Shambler into your own personal Mr. Potatohead ...

shambler_karl