Jump to content

Set Shape with script


Marcousik
 Share

Recommended Posts

How should I set a complete polymesh shape with a script on a model with 2 surfaces?

 

I construct the shape like this:

 

local surf1 = Model:GetSurface(0)

local surf2 = Model:GetSurface(1)

local Shape1 = PolyMesh(surf1)

local Shape2 = PolyMesh(surf2)

Model:SetShape(--- ??? ----)   

 

How to I set the two shapes on one model ?????

Thx for help

 

 

Link to comment
Share on other sites

mmh I don't get it to work.. Something must be wrong but I don't know what.

But I could get it running by creating 2 differents models, but maybe worse for performances.

Quote

    local roadModel = Model:Create()  

    --    roadModel:SetViewRange(Entity.FarViewRange)
        roadModel:SetShadowMode(0)
        roadModel:SetCollisionType(Collision.Scene)
 

        local surface = roadModel:AddSurface() 
        local surfaceB = roadModel:AddSurface() 
        local surfaceS = Surface:Create()

-- road:
        surface:AddVertex(v0, n, Vec2(0,0)) --0
        surface:AddVertex(v1, n, Vec2(1,0))     --1
        surface:AddVertex(v2, n, Vec2(1,1))     --2
        surface:AddVertex(v3, n, Vec2(0,1))     --3
        
        surface:AddTriangle(0,1,2)  
        surface:AddTriangle(0,2,3) 
        surface:Update()  

-- bankD 
        surfaceB:AddVertex(ve_1, n, Vec2(-1,0)) --0
        surfaceB:AddVertex(v0, n, Vec2(0,0))     --1
        surfaceB:AddVertex(v3, n, Vec2(0,1))     --2
        surfaceB:AddVertex(ve_2, n, Vec2(-1,1))     --3
        
        surfaceB:AddTriangle(0,1,2)  
        surfaceB:AddTriangle(0,2,3) 
        surfaceB:Update()  

-- bankG 
        surfaceB:AddVertex(v1, n, Vec2(1,0)) --4
        surfaceB:AddVertex(ve4, n, Vec2(2,0))     --5
        surfaceB:AddVertex(ve5, n, Vec2(2,1))     --6
        surfaceB:AddVertex(v2, n, Vec2(1,1))     --7
        
        surfaceB:AddTriangle(4,5,6)  
        surfaceB:AddTriangle(4,6,7) 
        surfaceB:Update()  

        surface:SetMaterial(self.RoadMaterial) 
        surfaceB:SetMaterial(self.BankMaterial)

--        roadModel:UpdateAABB(Entity.LocalAABB+Entity.GlobalAABB)

        local mat = Mat4()

        surfaceS:Add(surface, mat)
        surfaceS:Add(surfaceB, mat)
        surfaceS:Update()
        
         local shape = Shape:PolyMesh(surfaceS)        -- THIS RETURNS shape == nil      --  I don't know why
        roadModel:SetShape(shape)
        shape:Release()
 

 

 

 

Link to comment
Share on other sites

Just a few thoughts that may or may not help;

Quote

roadModel:UpdateAABB(Entity.LocalAABB+Entity.GlobalAABB)

Shouldn't it be;

roadModel:UpdateAABB(Entity.LocalAABB | Entity.GlobalAABB)

Unless LUA is different to C++ in this aspect...  I see it's commented out here though..

Does surface:Update() update the vertex normals?  I'm not sure if that's needed to create a polymesh though...

Only other thing I can think if is too make sure the vertices aren't too close together?  I recall something ages ago where this caused a null polymesh for me.

Link to comment
Share on other sites

Quote

Just a few thoughts that may or may not help;

  Quote

roadModel:UpdateAABB(Entity.LocalAABB+Entity.GlobalAABB)

Shouldn't it be;


roadModel:UpdateAABB(Entity.LocalAABB | Entity.GlobalAABB)

> I got it from there: https://www.leadwerks.com/learn?page=API-Reference_Object_Surface_Add

Quote

 I'm not sure if that's needed to create a polymesh though...

> No it is not needed.

 

Thx for reply.

I don't know where is the problem. In the editor you can easily collapse models with different surfaces/materials and generate a polymesh shape.

But seems not possible in script. Because collapsing make the entire model with one unique material.

I got the shape to be right generated with this:

Quote

        surface:Add(surfaceB, mat)
        surface:Update()
        
         local shape = Shape:PolyMesh(surface)        -- THIS RETURNS the right shape for the 2 surfaces

So I created 2 different models with each one one surface and it runs ok.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...