Monday, 30 June 2014

Tip for Quaternion Multiplication by Hand

Here is a technique for multiplying two quaternions by hand so you do not have to remember the formula mentioned in my introduction to quaternions post [link].

If you are multiplying P x Q where P and Q are two quaternions create a grid as shown below.

Write the first quaternion of the multiplication in a column on the left side of the grid and then write the second quaternion in a row at the top of the grid.


Metasequoia Script – Using Quaternions to Rotate Points

You can use a Python script in Metasequoia to demonstrate the quaternion sandwich product rotating a point.

I have set up a Metasequoia document as shown below.

Demonstate quatenion sandwich product in Metasequoia 4

Saturday, 28 June 2014

A Gentle Introduction to Quaternions

The internet doesn’t have enough tutorials about quaternions so I thought I’d add another one. ;-)

You only need to learn the basic arithmetic and some formulae to enable you to get the hang of quaternions.

The multiplication sign, x in this article stands for ordinary, everyday multiplication.

Remember to to do the multiplications first in any sum before doing the additions.

Firstly I’ll introduce you to some unusual numbers that you don’t see in everyday life.

Lets call them alphabet numbers.

Tuesday, 24 June 2014

Building a Simple C program in ZinjaI

Zinjai [link] is a C and C++ integrated development environment or IDE.

An IDE contains a text editor to write code, a compiler to compile code, a linker to build compiled code into an executable file and a debugger to pause a program during execution to allow a programmer to examine the program’s state.

ZinjaI screenshot

It is a Spanish language program but there is a version mostly translated into English.

Note that there is a newer version (20140620) available but it seems to have a bug that does not allow the user interface to be set to English. Update 25 Jun 2014: This bug has been fixed.

Zinjai was created for teaching programming so is good for beginners to use.

One useful feature is that you do not have to create a project to test simple C or C++ code. Just type it in and run it.

Zinjai uses the MingW GNU compilers and tools to compile and build programs. You need to know this if you download other code libraries to use with your programs.

In my post about MQO viewers [link], I posted a site where you can download the C source code for GLMetaseq.

Download from that site [link], near the bottom of the page.

We will build the sample_GL program in Zinjai so we can view a Metasequoia *.mqo file.

Sunday, 22 June 2014

Metasequoia Script – Import one of your own modules

Sometimes a Metasequoia Python script may contain many lines of code.

To keep the script simple you can split the script into several smaller scripts.

For instance you could have all your function definitions in a script of their own.

To access those functions you would import the script containing your functions into your main script the same as we have been doing for Python’s inbuilt modules such as “math”.

The script you import must have a filename that is a valid Python identifier so cannot start with a number and use only letters or numbers or the underscore, ‘_’.

The script file must have the extension ".py".

The script you import must not have any executing code or only have executing code in an “if __name__== “__main__”:” block.

For Metasequoia 4 the script or scripts you import must be in the same folder with the main script.

If you use Metasequoia’s MQSystem classes in the script you import, in that script you must explicitly import the MQSystem module as follows or you will get errors.

import MQSystem

Saturday, 21 June 2014

Metasequoia Script – Display an OpenFile Dialog

This script shows how to display an OpenFile dialog in Metasequoia 4.

Metasequoia 3 doesn’t have the MQWidget classes so this script is only for Metasequoia 4.

You use an OpenFile dialog to get a filename (actually the full path to a file) for your script.

Once your script has a filename you could use standard Python code to read the file.

You could, for example, write a script to open a 3D file format that Metasequoia does not support.

Friday, 20 June 2014

Metasequoia 4.2.2 User Interface Customisation

By default Metasequoia 4 ships with four predefined edit modes.
  • Beginner
  • Modeling (String)
  • Modeling (Icon)
  • Mapping
The edit mode setting determines which items appear in the command panel.

A “Customize” option has been added to the Edit Mode dropdown menu in Metasequoia 4.2.2.

Customize option added to Edit Mode menu

Metasequoia Script – Script Template

See this post [link] for the basics of using Metasequoia’s Script Editor.

Here is a Python script you can use as a starting point for your scripts.

Learning fragMOTION part 4

In TRLE games the gunflash for the shooting animations of enemies is an object that is linked to a particular mesh number of the enemy object.

Usually you can guess that the mesh the gunflash is linked to is the gun mesh.

That is, the gunflash is positioned x, y, z units from the origin of the gun mesh.

Gunflash positioning

You can use fragMOTION to be sure which mesh the gunflash is linked to by changing the rotation of the mesh and seeing if the gunflash position rotates too and stays in the correct position relative to that mesh.

Tuesday, 17 June 2014

MQO viewers

A collection of programs that can load and display Metasequoia *.mqo files.

Changing a TRLE meshtree with TRWad Reorganizer

In Tomb Raider 4 the gunflashes are linked to a particular mesh number of the animating object’s skeleton (meshtree). For instance the SAS slot links the gunflash to mesh number 7 of the animating object in that slot. Mesh number 7 is the mesh of the gun.

See this post [link] for how to find which mesh the gunflash is linked to by adjusting the shooting animation using fragMOTION.

If, in the SAS slot, you replace the SAS animating object with a different enemy, the gunflash may appear at the wrong place because mesh 7 of the new enemy is not the gun mesh.

So one reason to change the mesh order is to have the gunflash appear in the correct position.

TRWad Reorganizer [link] is a program that can change the order of the meshes in an animating object’s meshtree.

Changing the order of the meshes usually ruins the existing animations but the magic of TRWad Reorganizer is that it adjusts the animation’s keyframes to match the new mesh order so the animations are not ruined.

Monday, 16 June 2014

Metasequoia Script – Mikoto bdef bone influence

See this post [link] for the basics of scripting in Metasequoia.

In this post [link] I talk about how Mikoto assigns vertices to a bone using the geometry of the triangle created in Metasequoia for bdef meshes without using anchors.

To help visualise which vertices will be bound to a bone I wrote a script that shows the zone of influence of each bone.

The Metasequoia Python API doesn’t have routines to create Primitive objects so rather than create an object in code this script requires a Primitive to be created in Metasequoia which it can copy.

The Primitive object must be named capsule and have its properties set as shown in the screenshot below.

Create a capsule primitive with these settings

Sunday, 8 June 2014

Metasequoia 4.2 *.mqo file includes a thumbnail

Be aware that Version 4.2.1 of Metasequoia embeds a thumbnail image in an *.mqo file by default.

This means a large increase in the size of the *.mqo file.

It may also make the *.mqo file incompatible with some programs.

Since version 4.1 was uninstalled when I installed version 4.2.1 I cannot check whether version 4.1 also saved a thumbnail in the *.mqo.

You can disable this feature by clicking File>Configuration>File and unchecking “Embed a thumbnail”.

Go to Configuration to disable saving a thumbnail image

Make sure Embed a thumbnail is unchecked

Animating with Mikoto – part 8

To use the bone deformation method in Mikoto the name of the object containing the mesh to be deformed must begin with bdef:. Do not forget the colon :.

Our model’s skin is composed of separate meshes so to make it easier to demonstrate the deformation I will merge all the skin meshes into a single object.

In Metasequoia, click “Misc” in the Object Panel and click “Show All” to make all objects visible and then hide the “bone” object.

Click “Misc” in the Object Panel and click “Merge all visible”.

Merge skin meshes into one mesh

Click OK on the dialog to merge the skin meshes into one mesh.

One skin mesh

Saturday, 7 June 2014

Metasequoia Script–Lots of cubes

See this post [link] for the basics of using Metasequoia’s Script Editor.

I found an interesting script at this Japanese blog [link].

Animating with Mikoto – part 7

We used the closest bone method to assign our character’s meshes to the bones in the skeleton.

When a model is composed of separate mesh objects as ours is you can specify which bone a mesh is bound to by adding the bone name to the mesh object’s name separated with a hyphen (dash), “-”.

As an example I have bound the “Head (31)” object to the “foot[R]” bone by changing the object name to “Head (31)-foot[R]”.

Add bone name to object name to bind to that bone

In Mikoto the head no longer moves when the “head” bone is moved but only when the “foot[R]” bone is moved.

Head no longer moves with closest bone

Head rotates with right foot

Of course you would not bind the head mesh to the foot. I only did this to illustrate how this new method of binding meshes to bones overrides the closest bone.

The technique we have been using so far has not changed the shape of any of the meshes.

This method is all you need for some objects but for most human and animal characters you want to make the meshes bend smoothly at the joints such as elbows and knees etc.

To do this in Mikoto you have two choices, bone deformation (bdef) or spherical deformation (sdef).

prev | next

Friday, 6 June 2014

Metasequoia Script–Sierpinski Triangle Pyramid

See this post [link] for the basics of using Metasequoia’s Script Editor.

I found an interesting script at this Japanese blog [link].
# fractal generate

doc = MQSystem.getDocument()

num = doc.numObject
obj = doc.object[0]

# field

x = 100
y = 100
z = 100
rn = 4 # recursive number

# Primitive

p01 = MQSystem.newPoint(x/2,y,z/2)
p02 = MQSystem.newPoint(0,0,0)
p03 = MQSystem.newPoint(x,0,0)
p04 = MQSystem.newPoint(x,0,z)
p05 = MQSystem.newPoint(0,0,z)

# function fractal()

def fractal(number,p1,p2,p3,p4):

  if number == 1:
    v = []
    v.append( obj.addVertex(p1) )
    v.append( obj.addVertex(p2) )
    v.append( obj.addVertex(p3) )
    v = []
    v.append( obj.addVertex(p1) )
    v.append( obj.addVertex(p3) )
    v.append( obj.addVertex(p4) )
    # bottom
    v = []
    v.append( obj.addVertex(p4) )
    v.append( obj.addVertex(p3) )
    v.append( obj.addVertex(p2) )
    p5 = MQSystem.newPoint((p1.x + p2.x)/2, (p1.y + p2.y)/2, (p1.z + p2.z)/2)
    p6 = MQSystem.newPoint((p2.x + p3.x)/2, (p2.y + p3.y)/2, (p2.z + p3.z)/2)
    p7 = MQSystem.newPoint((p3.x + p1.x)/2, (p3.y + p1.y)/2, (p3.z + p1.z)/2)
    p8 = MQSystem.newPoint((p3.x + p4.x)/2, (p3.y + p4.y)/2, (p3.z + p4.z)/2)
    p9 = MQSystem.newPoint((p4.x + p1.x)/2, (p4.y + p1.y)/2, (p4.z + p1.z)/2)
    p10 = MQSystem.newPoint((p4.x + p2.x)/2, (p4.y + p2.y)/2, (p4.z + p2.z)/2)
# endfunction fractal()



Make sure you have an empty Scene in Metasequoia by clicking File>New then open the Script Editor and paste the code into the upper input pane of the editor.

Paste the code into the Script Editor's input window

Press F5 or Script>Run to execute the script and create the object.

Execute the script to create the object

Thursday, 5 June 2014

Decompiling Python programs

The EditWad program [link] was written in Python 2.5 and packed into an *.exe file using py2exe [link].

Packing a Python program into an *.exe file means the end user doesn’t need to have Python installed on their PC to run the program.

Because Python programs are compiled to bytecode and not machine code it should be easier to decompile a Python program more easily than a program that is compiled to machine code like a FreePascal progam or a C++ program.

Learning fragMOTION part 3

To view an animation in fragMOTION, click on the Animations tab, click on the animation name (in this case “Animation”) and then click the play button or click and drag the Frame slider.

Play animation

Rather than creating a new animation by posing the model at various frames (keyframing) , I’m am going to try an import one from a BioVision *.bvh file the same as I did with Mikoto [link].

If successful then maybe it’s possible to save the animation to MilkShape 3d *.ms3d and import it into a TRLE *.wad file with Daro Anim Maker or a *.TR4 file with Fexanim.

Sunday, 1 June 2014

Mikoto2x instructions

Mikoto2x [link] [link2] is a program to convert animations created in Mikoto to the Direct3D *.x text file format.

Mikoto is a program that can be used to animate models created in Metasequoia.

The model has to include special objects and object names for animation to be possible in Mikoto. See the tutorial here [link].

Mikoto2x requires the vertices of the character mesh to be assigned to the bones using the anchors method in Metasequoia.

Anchors are boxes that envelop all the vertices that are to be assigned to a bone.

Reading the translated “readme.txt” [link] it may required that the effector must be bdef: only and that the character mesh must be in a single object but I have not had time to clarify this.

I will just show how to use Mikoto2x at this time and update the post later with the requirements for the model.

Create a new folder somewhere on your PC and copy the following files from Mikoto2x’s sample folder to the new folder.
  • “kobito.mqo”
  • “kobito.m2x”
  • “df_00.bmp”
  • “df_01.bmp”
I will be using the freeware MetasequoiaLE R3.0.

It is yet to be confirmed whether Mikoto2x is compatible with *.mqo files saved from Metasequoia 4. Metasequoia 4 default *.mqo files are version 1.1 whereas Metasequoia 3 default *.mqo files are version 1.0.

Open “kobito.mqo” in Metasequoia.

Open model in Metasequoia