grrr the wiki page looses the bb codes I added, while it showed them perfectly in the preview.
here is what the page should look like :
Creating a minion : a short tutorial.
This tutorial is intended to let people easily add a model to the world as a minion.
To start you need a wavefront
.obj model with uv mapping and a
.png image containing the textures.
the png files are located in
\Terasology\src\main\resources\org\terasology\data\textures
the obj files are located in
\Terasology\src\main\resources\org\terasology\data\mesh
so start by copying your files to the appropriate folder / dir.
*note : there probably should be different folders for mods, so the location might change in the future.
Lets say your model is called
tuttest.obj, and your image is called
tuttestimage.png, as an example used throughout this tutorial.
The first thing to create then is a material.
Materials are located in
\Terasology\src\main\resources\org\terasology\data\materials
A material is basically a
json file which tells Terasology which image to load as a texture for your model.
Copy the file called
monkeyHead.mat and paste it with the name
tuttest.mat,
IMPORTANT! : notice that the name of the material needs to be different then the name of the image, else you will get an error if I remember correctly.
Now open the file
tuttest.mat, it will look like this :
Code:
{
"shader" : "engine:genericMesh",
"params" : {
"diffuse" : "engine:mhead",
"colorOffset" : [1.0, 1.0, 1.0],
"textured" : true
}
}
The important part here is the params, namely the line
Code:
"diffuse" : "engine:mhead",
which refers to the monkeyhead image mhead.png, so you want to edit that line to look like this :
Code:
"diffuse" : "engine:tuttestimage",
notice you don't specify the extension
.png, only the name of the file.
Save this file, you just created your first material,
congratulations!
Now we need to create a
prefab, which is another
json file where we will bring pieces of the puzzle together.
As we will use the miniion mod in this tutorial to render the model, the files will be located in
\Terasology\mods\miniion\prefabs
If you'd like to create your own mod, you have create a new folder / dir in the mods folder, and a new subfolder / subdir prefabs.
I'll get into more detail in another tutorial or in an update for creating a new mod.
In the prefabs folder / dir of miniions you will find some
prefabs.
Copy 1 of them, for example
gelatinousMinion.prefab, and paste it as
tuttest.prefab, similar to copying the material.
Then open the file, it will look like this :
Code:
{
"name": "miniion:gelatinousMinion",
"Minion" : {
"icon" = "gelcube"
},
"Location" : {},
"Mesh" : {
"mesh" : "engine:testmonkey",
"material" : "engine:monkeyHead"
},
"CharacterMovement" : {
"faceMovementDirection" : true
},
"SimpleMinionAI" : {},
"AABBCollision" : {
"extents" : [0.5, 0.5, 0.5]
},
"CharacterSound" : {
"footstepSounds" : ["Slime1", "Slime2", "Slime3", "Slime4", "Slime5"],
"footstepVolume" : 0.7
},
"Inventory": {
"itemSlots": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
},
"AccessInventoryAction": {}
}
A couple lines are of intrest to us at this point :
first we want to give our model a name, you do this by modifying the line :
Code:
"name": "miniion:gelatinousMinion",
into :
Code:
"name": "miniion:tuttestMinion",
this is merely an example, tuttestMinion is a index / key we will use later in the factory to reference our model.
notice the prefix miniion: which specifies what mod the prefab belongs to. Change this if you created your own mod.
Now that we changed the name, we need to specify the mesh and material to use.
Modify the line :
Code:
"mesh" : "engine:testmonkey",
into :
Code:
"mesh" : "engine:tuttest",
to let Terasology know you want it to render the
tuttest.obj file.
then modify the line under it :
Code:
"material" : "engine:monkeyHead"
into :
Code:
"material" : "engine:tuttestimage"
notice again that I didn't specify the extension
.mat again,
this line will tell Terasology to use the
tuttestimage.mat file to color our model.
ignore the prefix engine: for now, just let it be.
Congratulations, you just finished creating a model for the miniions mod (or your own mod).
Now what's left is actually telling Terasology where to render your model in the world.
That's where the miniion mod comes in handy, I created a factory located in
\Terasology\src\main\java\org\terasology\mods\miniions\componentsystem\entityfactory
called
MiniionFactory.java
Open that file and you will see somthing like this :
Code:
package org.terasology.mods.miniions.componentsystem.entityfactory;
import org.terasology.components.LocationComponent;
import org.terasology.components.MeshComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.entitySystem.EntityRef;
import org.terasology.utilities.FastRandom;
import javax.vecmath.Vector3f;
/**
* copied from @author Immortius
* modified by @author Overdhose
*/
public class MiniionFactory {
private static final Vector3f[] COLORS = {new Vector3f(1.0f, 1.0f, 0.2f), new Vector3f(1.0f, 0.2f, 0.2f), new Vector3f(0.2f, 1.0f, 0.2f), new Vector3f(1.0f, 1.0f, 0.2f)};
private FastRandom random;
private EntityManager entityManager;
// generates minion cubes for minion toolbar
public EntityRef generateMiniion(Vector3f position, int index) {
EntityRef entity = null;
switch (index) {
case 0: {
entity = entityManager.create("miniion:monkeyMinion1");
break;
}
case 1: {
entity = entityManager.create("miniion:monkeyMinion2");
break;
}
case 2: {
entity = entityManager.create("miniion:monkeyMinion3");
break;
}
case 3: {
entity = entityManager.create("miniion:monkeyMinion4");
break;
}
case 4: {
entity = entityManager.create("miniion:monkeyMinion5");
break;
}
case 5: {
entity = entityManager.create("miniion:monkeyMinion6");
break;
}
case 6: {
entity = entityManager.create("miniion:monkeyMinion7");
break;
}
case 7: {
entity = entityManager.create("miniion:monkeyMinion8");
break;
}
case 8: {
entity = entityManager.create("miniion:monkeyMinion9");
break;
}
default:
entityManager.create("miniion:monkeyMinion1");
}
if (entity == null) {
return null;
}
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
loc.setWorldPosition(position);
loc.setLocalScale(((random.randomFloat() + 1.0f) / 2.0f) * 0.8f + 0.2f);
entity.saveComponent(loc);
}
MeshComponent mesh = entity.getComponent(MeshComponent.class);
if (mesh != null) {
int colorId = Math.abs(random.randomInt()) % COLORS.length;
mesh.color.set(COLORS[colorId].x, COLORS[colorId].y, COLORS[colorId].z, 1.0f);
entity.saveComponent(mesh);
}
return entity;
}
public FastRandom getRandom() {
return random;
}
public void setRandom(FastRandom random) {
this.random = random;
}
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
Now all you have to do is modify a line in the switch statement to add your own model,
and you will be able to summon your creation using the miniion toolbar.
let's say you want to summon your model in position 1 on the toolbar,
just modify the line :
Code:
case 0: {
entity = entityManager.create("miniion:monkeyMinion1");
break;
}
into
Code:
case 0: {
entity = entityManager.create("miniion:tuttestMinion");
break;
}
and that's all you need to do.
If you now launch the game, and activate the minionbar by pressing the "x" key and left click on a block while the first slot is selected,
it should show you the model you just created in the game. If you see the toolbar shows an icon but you don't see a model, most likely the engine had a problem reading your obj file and generated an error in the log.
Please try to locate the error and let us know on the forums / irc what the error is.
If all went well you should be seeing your model in game, so take a screeny and let us see your creation.
The explanation might seem a bit long, but it's actually quite simple once you done it 1 time,
it takes max 5 minutes to create another model.