Community Forum

Information about SplitShapes

Forum Overview >> Scripting

CategoryScripting
Created28.06.2015 16:55


Michael Lachner (Unknown) 28.06.2015 17:11
Hi all,

i am experimenting around with SplitShapes. I have a small piece of code, that gives me a shape and the corresponding information:

shape, minY,maxY, minZ, maxZ = findSplitShape(x,y,z, nx,ny,nz, yx,yy,yz, 5, 5);
if shape ~=0 then
self.infoText = self.infoText .. "Shape-Volume: " .. getVolume(shape) .. ".\n";
self.infoText = self.infoText .. "Shape-Mass: " .. getMass(shape) .. ".\n";
splitType = SplitUtil.splitTypes[getSplitType(shape)];
self.infoText = self.infoText .. "SplitType:\n";
self.infoText = self.infoText .. " Name: " .. splitType.name .. ".\n";
self.infoText = self.infoText .. " splitType: " .. splitType.splitType .. ".\n";
self.infoText = self.infoText .. " pricePerLiter: " .. splitType.pricePerLiter .. ".\n";
self.infoText = self.infoText .. " woodChipsPerLiter: " .. splitType.woodChipsPerLiter .. ".\n";
if splitType.allowsWoodHarvester ~= true then
self.infoText = self.infoText .. " ... and does not allow a wood harvester\n";
else
self.infoText = self.infoText .. " ... and does allow a wood harvester\n";
end;
end;

it only works partly. Fir trees (the ones the harvester can chop) are not shown, neither the ones already present on the maps, nor the placeable ones. Information is displayed on all other trees.
The name denotes the type of the tree, maple, ash, etc. What does the split type say? It looks like it changes between tree types.
... so what am i doing wrong? Ho do i get the information on the fir trees?

Thanks in advance!

elmike

Emil Drefers (Unknown) 29.06.2015 10:11
Hi,

maybe you are using wrong directions for testing.

A good idea might be to render debug lines to visualize where you are testing for a plsit shape.

The arguments to the function findSplitShape define a rectangle.

A corner point is defined by x,y,z.
The up vector of the plane defined by the rectangle is nx,ny,nz.
yx,yy,yz defines one direction of the plane/rectangle
(The second direction can be calculated by using the cross product over the first two vectors.)
The size of the rectangle is defined by the two final arguments.

Just open a chainsaw.i3d, the script file and try to understand what means what and how things are aligned.
http://ls-mods.de/scriptDocumentation.php?lua_file=handTools/Chainsaw


Cheers,
Emil





Michael L. (Unknown) 01.07.2015 06:49
Hi Emil,

thanks for the quick reply!

I was not t aware, that this function defines a flat rectangle, i was expecting it to define a three-dimensional box, that's why i chose the values so unfitting.

So i managed to get this working, with the normal pointing in y-Direction and thus covering a horizontal area in front of the player. Fir trees are also working now.

Another question on getMass: As long as the tree is still standing, the function always returns 1. When i chop it down, it returns a different value. What is the unit here? Looks like tons to me, considering the weight of a fresh cut, healthy tree.
And what does the splitType say? It looks like it is different for every kind of tree, but it doesn't change when i cut a tree into smaller pieces.

Regards,
elmike

Emil Drefers (Unknown) 01.07.2015 07:05
Hi,

glad you got it working :)

Yes, the unit of getMass() is tons.
Still standing trees are not dynamic, so that's probably the reason why the mass is always 1 in this case.

Yes, splitType is used to distinguish between different types of trees.
They have different attributes concerning
- price per liter
- woodChips per liter
- can be chopped down by a harvester

The spliType can also be found by opening an i3d of a tree with a texteditor

You could also register new splitTypes, if neccessary.

Cheers,
Emil

Rolf Nothhelfer (TracMaxx) 22.01.2016 13:09
Hi,

I want to get information how to get the growthState of a tree, to see if it is worth cutting it. The variable "shape" only contains a number(Id?), and the splitType does not contain the growthState parameter.

Thanks for any hints
TracMax

Emil Drefers (Unknown) 28.01.2016 08:35
Hi,

you could try the following:

Get the shape id, which you already have ;)
Check the following table:
g_currentMission.plantedTrees

it should contain another table, which holds all growing trees:
g_currentMission.plantedTrees.growingTrees

you could make a loop through that table and check if the shapeId which you queried is present in that table:
e.g.
for i,tree in pairs(g_currentMission.plantedTrees.growingTrees) do
if tree.node == shapeId then
print(tostring(shapeId).." is a growing tree");
end
end

Cheers,
Emil


Fabio Celsa (fcelsa) 04.03.2016 12:46
Hello,
I have found useful information in this thread, findSplitShape is ok for me if I use cutNode of chainsaw as reference, like original ChainSaw.lua.

But what I want now, and are not able, is to use findSplitShape with player only, to find small piece of wood on terrain, and move around this piece, and a first problem is just findSplitShape, because a can't find any piece of wood in front of player, i'm confused about his parameters, can you write example for me?

Thanks for your time.
fcelsa


Emil Drefers (Unknown) 07.03.2016 07:47
Hi,

findSplitShape() works very similar to cutSplitShape().
you need a position and two vectors to define a plane (quad) whcih is used to search for split shapes.

The following lines are taken from the WoodHarvester.lua

local x,y,z = localToWorld(self.cutNode, 0.3,0,0);
local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0);
local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0);
local shape, minY, maxY, minZ, maxZ = findSplitShape(x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ);

If you open the ponsseScorpion.i3d and find the cutNode (3>4) you will understand what the parameters mean.

x,y,z = position of cutNode
nx,ny,nz = 'normal direction' of the cutting plane (a vector upright to the plane)
yx,yy,yz = one direction/vector of the plane
cutSizeY/Z are self explanatory, I would say ;)

Cheers,
Emil

Fabio Celsa (fcelsa) 09.03.2016 22:17
Hello,
findSplitShape is almost ok, but when I try to link shape to player.toolsRootNode the shape disappear, but when unlink the piece of wood not return... I'm missing something :)

piece of code:

if Input.isKeyPressed(Input.KEY_KP_1) and self.targetShape ~= nil and self.targetShape ~= 0 then
local nodeId = self.targetShape;
link(self.playerToolsNode, nodeId);
setVisibility(nodeId, true);
self.cuttedNodeId = nodeId;
local x,y,z = getWorldTranslation(self.playerToolsNode);
x,y,z = worldToLocal(getParent(nodeId), x,y,z);
local a,b,c = getTranslation(nodeId);
setTranslation(nodeId, a-x,b-y,c-z);
end;

if Input.isKeyPressed(Input.KEY_KP_2) then
unlink(self.cuttedNodeId);
end;

I studied WoodHarvester.lua and HighPressureWasherPlaceable.lua, but it is likely that I left something.

anyone has tried to do something to manipulate the logs cut in an easy way ??

Thanks for your time.
fcelsa



Note: Log in to post. Create a new account here.