Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts

Monday, 21 June 2021

WIP: WAD2 Remapper

Version: 1.0

Status: Released

 

A program for the Tomb Raider Level Editor (TRLE) community.

The WadTool program included with Tomb Editor does not yet have a remap feature.

EDIT 23 July 2021: Remapping ability added to WadTool version 1.3.16. (Tools>Mesh Editor)

Remapping is where a vertex’s index number is changed so it is below a certain limit.

This is needed for vertices in the LARA_SKIN meshes that connect to LARA_JOINTS meshes.

WadTool uses a new file format, *.WAD2, which is incompatible with StrPix, the program used to remap vertices for the old wad format, so I wrote this program.

See GitHub for source code and release. [link]

If a 32 bit version of the program is needed please let me know in the comments or at the Level Editor forum at tombraiderforums.com.

Please do not ignore the warning about always having a backup copy of your WAD2 file.

This program may corrupt the file.

 

Usage:

Open your WAD2.

Expand a moveable in the treeview.

Select a mesh.

Swap vertices as required.

There are two ways to swap vertices.

  1. Left click a vertex to select it and then hold "Control" and left click on another vertex to swap them.

  2. Enter the two vertex numbers to swap in the boxes and click "Swap".

Save the WAD2. Do not save over your WAD2 unless it is a copy.

 

3D Viewport Controls:

Left mouse button - Select vertex

Right mouse button - Rotate view

Middle mouse button - Pan view

Mouse wheel - Zoom view

Note that sometimes you might click through a mesh and select the vertex hidden behind the mesh.

 

Screenshot

 

Built using free Delphi Community Edition 10.3.3.  (A Firemonkey 3D project)

Monday, 31 August 2020

Delphi bug: Invalid Window Handle Error 1400

My program developed a bug where sometimes on exit an access violation error and invalid window handle error would appear.

invalidhandle

The bug wasn’t totally random but occurred when some sectors in a grid were selected but not when other sectors in the same grid were selected. The grid was an image.

The program uses several TMemo components to display information pertaining to the sector selected and the number of lines displayed in each TMemo varies for each sector.

By trial and error it was found that the bug was caused by appending strings to a TMemo which happened to be the seventh and last TMemo on the form.

I am not skilled enough to get to the bottom of the cause but it seems the bug was caused by the number of lines appended to the TMemo and the length of the lines. No exceptions were raised here though.

Fewer lines no problem. More lines no problem. Shorter lines no problem.

I don’t know why but a TMemo.Lines.Text length between 284 and 308 caused the error.

I fixed the error by ensuring the text length was not between these two values.

Using Delphi Community Edition 10.2.3 on Windows 10.

Friday, 17 May 2019

Reading .zip files in Delphi and Python

Metasequoia uses a new default file format from version 4.7 which has extension *.mqoz.
This a just a *.zip file that contains an *.mqo file and a thumbnail.jpg file and maybe an *.mqx file.

Below are examples in Delphi 10.2 and Python 2.7 that show how to read the *.mqo inside the *.zip.

Sunday, 5 May 2019

Automatic mouse cursor move program

I needed a program to move the mouse cursor every so often to stop a PC from timing out while I was watching videos.

I didn't have admin rights for the PC so I could not adjust the timeout settings.


Thursday, 25 October 2018

Delphi Classes - fields

Some information I didn’t know about declaring fields in classes.

The var keyword is optional. However, if it is not used, then all field declarations must occur before any property or method declarations. After any property or method declarations, the var may be used to introduce any additional field declarations.
Source: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Fields_(Delphi)


If a member's declaration appears without its own visibility specifier, the member has the same visibility as the one that precedes it. Members at the beginning of a class declaration that do not have a specified visibility are by default published, provided the class is compiled in the {$M+} state or is derived from a class compiled in the {$M+} state; otherwise, such members are public.
Source: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Classes_and_Objects_(Delphi)

 

Thursday, 3 May 2018

Delphi 10.2 TQuaternion3D Example

Delphi’s System.Math.Vectors unit contains the TQuaternion3D class.

There is no information about the class in the Help so I post some code here so I remember how to use the class.

Following are some code snippets showing how to use quaternions to transform the mesh vertices in a model according to a skeletal hierarchy.

The procedures are used to build the models from old classic Tomb Raider games and export them to a 3D modelling program.

In Tomb Raider the animation data is stored as an (x,y,z) offset for the root bone and YXZ Euler angles for the rotations of all the bones.

In Tomb Raider a right handed coordinate system is used but the –Y axis is up so usually a further transformation is needed to get the models the right way up in other programs.

Here I do a 180 degree rotation about the X axis.

It is important to do this transformation last since then you don’t have to worry about adjusting the angles or offsets.

The code snippets also use System.Generics.Collections TStack and TList.

I also include a small example for the System.Math.Vectors TMatrix3D class which similarly has no Help topic.

Monday, 1 May 2017

Delphi TOpenDialog option ofExtensionDifferent


ofExtensionDifferent doesn’t appear to be set in Windows 8.1.

The following example from [link] fails.

procedure TForm1.Button1Click(Sender: TObject);
var 
Done: Boolean;
filenamestring : String;
begin
  OpenPictureDialog1.DefaultExt := GraphicExtension(TIcon);
  filenamestring := GraphicFileMask(TIcon);
  OpenPictureDialog1.FileName := filenamestring;
  OpenPictureDialog1.Filter := GraphicFilter(TIcon);
  OpenPictureDialog1.Options := [ ofFileMustExist, ofHideReadOnly, ofNoChangeDir ];
  Done := False;
  while not Done do
  begin
  if OpenPictureDialog1.Execute then
    begin
    if not (ofExtensionDifferent in OpenPictureDialog1.Options) then
      begin
      Application.Icon.LoadFromFile(OpenPictureDialog1.FileName);
      Done := True;
      end
    else
//      OpenPictureDialog1.Options := OpenPictureDialog1.Options - ofExtensionDifferent;
    end
  else { User cancelled }
    Done := True;
  end;
end;
 
 
CodeTyphon (Lazarus fork) doesn't have this problem. 
 

Sunday, 28 August 2016

Delphi 10.1 Starter Edition Free Until 9 Sep 16

EDIT2: Embarcadero now offer a free full featured community version of Delphi for non commercial use.

https://www.embarcadero.com/products/delphi/starter 

EDIT: Looks like Embarcadero have extended the offer after 9 Sep 2016 so try the promotional link below if interested because it might still be active.
The non-commercial, feature limited version of Delphi 10.1 is available for free for a limited time.
You need to register with Embarcadero before downloading the web installer.
The main installation will apparently involve a 2.2 GB download.
Delphi Starter Edition is a good IDE for beginners interested in learning Delphi.
Windows 7 or above required.
https://www.embarcadero.com/products/delphi/starter/promotional-download
Some discussion about it at
http://forum.lazarus.freepascal.org/index.php/topic,33792.0.html?PHPSESSID=lrhb3an0qjgqki5fejv42dgpq4