Jump to content

creating a mesh in lua


VicToMeyeZR
 Share

Recommended Posts

I am trying to create a mesh in real time but the mesh always just goes to 0,0,0 positon

 

function class:CreateObject(model)
local object=self.super:CreateObject(model)
object.model = CreateSphere(object.resolution, "0")

 

 

Is there a way to make it follow where the object is in the editor?

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

You can look at any of my Pi objects, but basically in the Update() method you can set the position of your mesh to the models position. Here is how I handle this.

 

function class:CreateObject(model)
   local object = self.super:CreateObject(model)
   object.model = model        -- this will save off the editor model so you can use it later
   object.sphere = CreateSphere(object.resolution, "0")


  function object:Update()
     -- I can't remember if these are the right names or not but you get the idea
     object.sphere:SetPosition(object.model:GetPosition())
  end
end

 

 

Also, to avoid the sphere being to large and covering up your editor model which prevents you from being able to click it to select it (you can still select it on the tree view side), I generally offset the sphere down 1/2 the size of it. This puts the editor model 1/2 way sticking out the top so I can still select it and move it around.

 

OR you could probably parent it. I avoid parenting because when I create objects in code when I'm in game mode I generally hide the editor model since it's not needed. It's basically used to just be able to move your objects you create in code when in editing mode. This is why I create that global game mode variable and check that in the Update() method in my Pi objects.

 

Also, be sure to free the objects you create in the free method. Or even if you delete the editor model your object that you created in code will stay in the scene.

 

Also note that if you try to create a body in lua code there is no way to get a collision method fired for that. I have a request in for this because it limits the usefulness of creating bodies in lua code.

Link to comment
Share on other sites

In the lua template for the LE wizard this is used to scale a cube.

 

 

ground=CreateCube()
ground:SetScalef(10.0,1.0,10.0)
ground:SetPositionf(0.0,-2.0,0.0)
ground:Paint(material)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

yeah, I know the cube, but what I was wondering since there is a deafult value of diameter for a sphere, wouldn't one think that to scale that you should be able to set the diameter, and not use a Vect3 for its size?

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

I'm not sure what it is you are trying to do but can't?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

surely if its a sphere you want you'd just have the one value as you'd scale it equally.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I meant:

 

if key=="diameter" then
   singlevalue = value
   object.model:SetScalef(singlevalue, singlevalue, singlevalue, object.model)
end

 

 

as you'd be scaleing in the x y and z equally

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

technically speaking, it only has one. Diameter is diameter..

 

Thats all I wanted to know. I jst saw in the wiki the default was 2, so I wasn't sure if it just set

Scalef(2,2,2, mesh)

 

Or if there was a magically function that did that for you, by just passing diameter. Because if you give it a different number for one of the size demensions, then its not a sphere any more, is a different shape.

 

(just trying to clarify something)

 

A sphere (from Greek σφαῖρα—sphaira, "globe, ball") is a perfectly round geometrical object in three-dimensional space, such as the shape of a round ball. Like a circle in three dimensions, a perfect sphere is completely symmetrical around its center, with all points on the surface lying the same distance r from the center point. This distance r is known as the radius of the sphere. The maximum straight distance through the sphere is known as the diameter of the sphere. It passes through the center and is thus twice the radius.

 

:P

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

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...