Author Topic: Some question ^^  (Read 5567 times)

0 Members and 1 Guest are viewing this topic.

Neolitik

  • Newbie

  • Offline
  • *

  • 1
    • View Profile
Some question ^^
« on: February 05, 2010, 09:37:40 PM »
Hello thank for all !

I want use GeeXLab for make mini game  ;D
I'm think that a great tool ! for this !
I' m not a super coder ( QI < 20  :P ) , but i have fun with code ( and lot of strees )

I' have a question for texturing a cube(make with HYP_Mesh.CreateBox (lua)) , i can texture it , it's ok ...
But can i texture just one face or 2 face with 2 different texture ... ?

french : ^^ " J'aimerai texturer un cube avec des textures differentes sur le face , est ce possible ? "   

Sorry for my english i'm french ^^

thank for all !

Alex

  • Newbie

  • Offline
  • *

  • 15
    • View Profile
Re: Some question ^^
« Reply #1 on: February 08, 2010, 02:18:02 AM »
Hi,

I tried to make box model out of 6 planes. The idea is to encapsulate 6 planes in parent object and make some method to change material of individual plane. So far box is created but it seams `HYP_Object.AddChild` is not enough to make a composite object.

here is test code:
Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<geexlab>
<scene name="test" show_ref_grid="TRUE" display_fps="TRUE">
<window_size width="960" height="640" width_offset="30" height_offset="50" fullscreen="FALSE" />
<ref_grid_color r="0.423" g="0.423" b="1.0" />
</scene>

<camera name="myCamera" fov="60.0" navigation_mode="EXAMINE" near_plane="1.0" far_plane="40000.0" inertia="FALSE">
<lookat x="0.0" y="0.0" z="0.0" w="1.0" />
<position x="0.0" y="31.0" z="-15.0" />
<bkg_color r="0.0" g="0.0" b="0.0" />
</camera>

<light name="myLight">
<ambient r="0.2" g="0.2" b="0.2" a="1.0" />
<specular r="0.1" g="0.1" b="0.1" a="1.0" />
<orientation pitch="-0.7" yaw="-0.70" roll="-0.70" />
<position x="1.0" y="40.0" z="1.0" />
<diffuse r="2.0" g="2.0" b="2.0" a="1.0" />
</light>

<texture name="imageJPG" filename="room.jpg" pixel_format="BGR" />       

<material name="constuctionPlaneMat" >
<add_texture name="imageJPG" />
</material>

<!--
<mesh name="plane1" shape_type="PLANE" render="TRUE" lighting="FALSE"
back_face_culling="FALSE" >
<plane x_size="150.0" z_size="128.0"  />
<position x="0.0" y="0.0" z="0.0" />
<orientation pitch="90.0" />
<attach_material name="constuctionPlaneMat" />
</mesh>
-->

<script name="logging.lua" filename="logging.lua" run_mode="INIT" />
<script name="class_structure.lua" filename="class_structure.lua" run_mode="INIT" />
<script name="box.lua" filename="box.lua" run_mode="INIT" />
<script name="test_init.lua" filename="test_init.lua" run_mode="INIT" />

<!--
<script name="update_frame.lua" filename="mainloop.lua" run_mode="FRAME" />
-->

</geexlab>


box.lua
Code: [Select]

CustomBox = GenericClass:new()

function CustomBox.new(self, width, height, depth)
log( " Creating new box ..."..width..', '..height..', '..depth )
local new = getmetatable(self).new(self)
if not depth then depth=0 end
if not height then height=0 end
if not width then width=0 end
new.width, new.height, new.depth = width, height, depth

-- replacing this call:
--    new.id = HYP_Mesh.CreateBox(width, height, depth, 1, 1, 1)
-- creating 6 planes to represent a box
local material = HYP_Object.GetId("constuctionPlaneMat")
new.sides = {}
new.sides[0] = new:CreatePlane(height, depth, 1, 1, CustomBox.PLANE_TYPE_YZ, material)
new.sides[1] = new:CreatePlane(height, depth, 1, 1, CustomBox.PLANE_TYPE_YZ, material)
HYP_Object.SetPosition(new.sides[0], width/2, 0, 0)
HYP_Object.SetPosition(new.sides[1], -width/2, 0, 0)

new.sides[2] = new:CreatePlane(width, depth, 1, 1, CustomBox.PLANE_TYPE_XZ, material)
new.sides[3] = new:CreatePlane(width, depth, 1, 1, CustomBox.PLANE_TYPE_XZ, material)
HYP_Object.SetPosition(new.sides[2], 0, height/2, 0)
HYP_Object.SetPosition(new.sides[3], 0, -height/2, 0)

new.sides[4] = new:CreatePlane(width, height, 1, 1, CustomBox.PLANE_TYPE_XY, material)
new.sides[5] = new:CreatePlane(width, height, 1, 1, CustomBox.PLANE_TYPE_XY, material)
HYP_Object.SetPosition(new.sides[4], 0, 0, depth/2)
HYP_Object.SetPosition(new.sides[5], 0, 0, -depth/2)

log( " Making box out of planes ..." )
-- reparent sides to form a box model
--    There is no method to create empty model obj. to hold this meshes, will try with gizmo ;)
local parent = HYP_Object.CreateGizmo()
for index = 0, 6 do
HYP_Object.AddChild( parent, new.sides[index] )
end

new.model = parent

return new
end

CustomBox.PLANE_TYPE_XZ = 0
CustomBox.PLANE_TYPE_XY = 1
CustomBox.PLANE_TYPE_YZ = 2

-- somehow HYP_Mesh.CreatePlane`s fifth parameter doesnot work ... so here we make a litle zbudz
function CustomBox.CreatePlane(self, w, h, w_segs, h_segs, plane_type, material)
local ret = HYP_Mesh.CreatePlane(w, h, w_segs, h_segs, PLANE_XZ)
log("new plane: "..w..', '..h..', '..plane_type)
log("mat id: ".. tostring(material))

HYP_Object.ClearAllMaterials(ret)
if material then HYP_Object.SetMaterial(ret, material) end
if plane_type == CustomBox.PLANE_TYPE_XY then
log("rotate about X")
HYP_Object.SetPitch(ret, 90, 2)
elseif plane_type == CustomBox.PLANE_TYPE_YZ then
log("rotate about Z")
HYP_Object.SetRoll(ret, 90, 2)
end
return ret
end

test_init.lua
Code: [Select]
our_box = CustomBox:new(1, 3, 7)

HYP_Object.SetPosition(our_box.model, 10, 0, 0)

`HYP_Object.SetPosition(our_box.model, 10, 0, 0)` is intended to move the whole box to new position, but i didn`t reparent those planes properly ...

logging.lua
Code: [Select]
LOG_USE_FILE = false

if LOG_USE_FILE == true then
local f = assert(io.open("app.log", "ab"))
f:write('\n\n\n\n\n\n\n\n\n\n\n\n\n logging started ..............................\n')
f:flush()
end

function log(msg)
HYP_Debug.Trace(msg)
if LOG_USE_FILE == true then
f:write(msg .. '\n')
f:flush()
end
end

class_structure.lua
Code: [Select]
GenericClass = {
new = function(self, obj)
local obj = obj or {}
setmetatable(obj, self)
self.__index = self
return obj
end
}

-- return a copy of the table t
function Clone(t)
local new = {}
local i, v = next(t, nil)
while i do
new[i] = v
i, v = next(t, i)
end
setmetatable(new, getmetatable(t) or {})
return new
end

-- return a copy of the table t
function DeepClone(t)
local new = {}             -- create a new table
local i, v = next(t, nil)  -- i is an index of t, v = t[i]
while i do
if type(v) == "table" then v = DeepClone(v) end
new[i] = v
i, v = next(t, i)        -- get next index
end
setmetatable(new, getmetatable(t) or {})
return new
end

JeGX

  • Global Moderator
  • Hero Member

  • Offline
  • *****

  • 544
    • View Profile
    • Geeks3D.com
Re: Some question ^^
« Reply #2 on: February 08, 2010, 09:44:55 AM »
Actually GeeXLab allows to create a cube with either an single material for all faces or with one material per face.
At least it's things work internally. I have to see if functions to play with the materials of a mesh cube are exposed.

JeGX

  • Global Moderator
  • Hero Member

  • Offline
  • *****

  • 544
    • View Profile
    • Geeks3D.com
Re: Some question ^^
« Reply #3 on: February 08, 2010, 09:47:22 AM »

french : ^^ " J'aimerai texturer un cube avec des textures differentes sur le face , est ce possible ? "   

Sorry for my english i'm french ^^

Pas de pb pour le français mon ami  ;)
Si tu veux parler en FR il te suffit de créer un post en FR. Je fais le support dans les deux langues, aucun problème pour moi.

Mais vu que tu as commencé ce post en english, il va falloir le terminer en english aussi  ;D

Alex

  • Newbie

  • Offline
  • *

  • 15
    • View Profile
Re: Some question ^^
« Reply #4 on: February 08, 2010, 05:09:09 PM »
Is it possible to group multiple meshes in a model using lua script ?

Or even group multiple models together in the same(local) coordinate space, that would be nice :D

JeGX

  • Global Moderator
  • Hero Member

  • Offline
  • *****

  • 544
    • View Profile
    • Geeks3D.com
Re: Some question ^^
« Reply #5 on: February 09, 2010, 05:00:59 PM »
Is it possible to group multiple meshes in a model using lua script ?
Yes, there is no particular problem.


Or even group multiple models together in the same(local) coordinate space, that would be nice :D
Never tried, but that should work...

Alex

  • Newbie

  • Offline
  • *

  • 15
    • View Profile
Re: Some question ^^
« Reply #6 on: February 10, 2010, 05:44:38 PM »
Is it possible to group multiple meshes in a model using lua script ?
Yes, there is no particular problem.


Or even group multiple models together in the same(local) coordinate space, that would be nice :D
Never tried, but that should work...

Which example describes this ?