Jump to content

TylerH

Members
  • Posts

    525
  • Joined

  • Last visited

Posts posted by TylerH

  1. This is one of the biggest downfalls of Leadwerks.

     

    Other than the end-user (us) making calls to the FreeXYZ() commands, Leadwerks seems to not handle any of its own memory; it leaves everything up to the Blitzmax Garbage Collector.

     

    In the real world of programming, alas C/C++/C99, and non managed/BASIC languages, there is no garbage collector, thus you must either manage your memory well or suffer from obvious leaks.

     

    I believe that if Leadwerks Engine managed its own memory, and smartly handled references, pointers, etc. and freed things on its own when appropriate, and not having any dependence at all on the BMX Garbage Collector, it would finally be on an equal plane to other engines on the market today.

    • Upvote 1
    • Downvote 3
  2. I am a bit annoyed by the fact the things like lights, emitters, and other "info" type entities need to have a gmf model and phy file. This is a waste of objects the scenegraph has to go through, and they aren't even removed when loaded in a game, causing issues with anything from doing line picks, to causing slow downs.

     

    I would like to formally request the ability to have entities that don't have to have a model with them. A light should be able to just be a light entity, an emitter be an emitter. If you want to attach an entity to a mesh, go right ahead, but it shouldn't be required...

     

    This is a major problem, and it should be dealt with timely.

  3. Lumooja's shot seems more fun than yours. Your shot, Ubu, just looks like every single other Leadwerks shot.

     

    No one seems to vary the ambiance enough to get a unique look. Lumooja seems pretty close to a nice, dramatic look, but it is a bit dark.

  4. Here is the newest version. This supports just about everything I want, except the vertices are not UV Mapped, so materials do not appear properly.

     

    It supports customizable aperture (like radius, but in geometry terms for square), tessellation (if you have a larger sized decal, you may need to increase tessellation, otherwise you will experience issues with the decal aligning to the terrain).

     

    The terrain alignment code now also uses TerrainElevation as opposed to TerrainHeight, so the decal can be smaller than a terrain tile and still be aligned relatively accurately. Ofcourse someone may come along and find an even better approahc to align the decal to the terrain, so I applaud everyone who wishes to improve this.

     

    Things that need done before this is usable:

    1) UV Coordinates

     

    Code:

    require("Scripts/class")
    require("Scripts/Math/math")
    require("Scripts/Primitives/Patch")
    require("Scripts/Math/Plane")
    require("Scripts/linkedlist")
    
    local class=CreateClass(...)
    
    function class:GetTerrain(world)
    local terrain
    for terrain in iterate(world.terrains) do
    	return terrain
    end
    end
    
    function class:InitDialog(grid)
    self.super:InitDialog(grid)
    
    group=grid:AddGroup("Terrain Decal")
    group:AddProperty("aperture",PROPERTY_FLOAT,"0.5,10,1","Aperture")
    group:AddProperty("tessellation",PROPERTY_FLOAT,"1,10,0","Tessellation")
    group:Expand(1)	
    end
    
    function class:CreateObject(model)
    local object=self.super:CreateObject(model)
    
    function object:CreateTerrainAlignedPatch()
    	if (object.patch ~= nil) then object.patch:Free() end
    
    	local terrain = self.class:GetTerrain(self.model.world)
    	local meterspertile=2.0
    	if terrain~=nil then
    		self.terrain = terrain
    		meterspertile=terrain.scale.x 
    	end
    
    	local pos = self.model.position 			
    
    		cx = pos.x - (self.aperture/2)
    		cz = pos.z - (self.aperture/2)
    		w = 1.0
    		d = 1.0
    		patch=CreatePatch(w*self.tessellation,d*self.tessellation)
    		patchsurf=patch:GetSurface(1)
    		patchsurf:Scale(Vec3(meterspertile*w*self.aperture,1.0,meterspertile*d*self.aperture))
    		patchsurf:Translate(Vec3((cx-Round(w/meterspertile/meterspertile)*meterspertile),0,(cz-Round(d/meterspertile/meterspertile)*meterspertile)))
    	--end
    
    	if terrain~=nil then
    		for v=0,patchsurf:CountVertices()-1 do
    			local t=patchsurf:GetVertexPosition(v)
    			t.y = TerrainElevation(terrain,t.x,t.z)+0.025--*terrain.scale.y+0.01				patchsurf:SetVertexPosition(v,t)
    		end
    	end
    
    	patch:UpdateLocalAABB()
    	patch:UpdateAABB()
    
    	--calculate texcoords/normals
    	for n=0,patchsurf:CountVertices()-1 do
    		t=patchsurf:GetVertexPosition(n)
    		if terrain~=nil then
    			patchsurf:SetVertexNormal(n,terrain:CalcNormal(t.x,t.z))
    		else
    			patchsurf:SetVertexNormal(n,Vec3(0,1,0))			
    		end			
    	end
    
    	patchsurf:UpdateTangentsAndBinormals()
    
    	if (self.material ~= nil) then
    		patch:Paint(self.material,0)
    	end
    
    	patch:SetParent(self.model,1)
    	self.patch = patch
    end
    
    function object:UnlockKeys()
    	self.super:UnlockKeys()
    end
    
    function object:SetKey(key,value)
    	if key=="material" then
    		self.materialname = value
    		self.material = LoadMaterial("abstract::"..value)
    		if (self.patch ~= nil) then				
    			self.patch:Paint(self.material,0)
    		end
    	elseif key=="aperture" then
    		self.aperture = tonumber(value)
    		self:CreateTerrainAlignedPatch()
    	elseif key=="tessellation" then
    		self.tessellation = tonumber(value)
    		self:CreateTerrainAlignedPatch()
    	else
    		return self.super:SetKey(key,value)
    	end
    end
    
    function object:GetKey(key,value)
    	if key=="material" then
    		return self.materialname
    	elseif key=="aperture" then
    		return self.aperture			
    	elseif key=="tessellation" then
    		return self.tessellation	
    	else
    		return self.super:GetKey(key,value)
    	end
    end
    
    function object:SetTarget(target,index)
    
    end
    
    function object:UpdateMatrix()
    	self:CreateTerrainAlignedPatch()
    end
    
    function object:ReceiveMessage(message,extra)
    	self.super:ReceiveMessage(message,extra)		
    end
    
    function object:Free(model)
    	self.super:Free()
    end
    
    object.aperture = 0.5
    object.tessellation = 1.0
    object:CreateTerrainAlignedPatch()
    
    end
    
    function class:Free()	
    self.super:Free()
    end
    

  5. Here is the working code. I need to figure out how to calculate the UV Coords properly, and scale the entire system down so the patch can be much smaller (for small decals, ofcourse B))

     

    require("Scripts/class")
    require("Scripts/Math/math")
    require("Scripts/Primitives/Patch")
    require("Scripts/Math/Plane")
    require("Scripts/linkedlist")
    require("Scripts/hooks")
    require("Scripts/loop")
    
    local class=CreateClass(...)
    
    function class:GetTerrain(world)
    local terrain
    for terrain in iterate(world.terrains) do
    	return terrain
    end
    end
    
    function class:InitDialog(grid)
    self.super:InitDialog(grid)	
    end
    
    function class:CreateObject(model)
    local object=self.super:CreateObject(model)
    
    function object:CreateTerrainAlignedPatch()
    	if (object.patch ~= nil) then object.patch:Free() end
    
    	local terrain = self.class:GetTerrain(self.model.world)
    	local meterspertile=2.0
    	if terrain~=nil then
    		self.terrain = terrain
    		meterspertile=terrain.scale.x 
    	end
    
    	local pos = self.model.position
    
    	if meterspertile==1 then
    		--[[x0=math.floor(self.model.aabb.x0)
    		x1=math.ceil(self.model.aabb.x1)
    		z0=math.floor(self.model.aabb.z0)
    		z1=math.ceil(self.model.aabb.z1)]]
    		x0=math.floor(pos.x)-1
    		x1=math.ceil(pos.x)+1
    		z0=math.floor(pos.z)-1
    		z1=math.ceil(pos.z)+1
    		cx=x0
    		cz=z0
    		w=x1-x0
    		d=z1-z0
    		patch=CreatePatch(w,d)
    		patchsurf=patch:GetSurface(1)
    		patchsurf:Scale(Vec3(w,1.0,d))
    		patchsurf:Translate(Vec3(x0,0,z0))
    	else
    		--[[x0=math.floor(self.model.aabb.x0/meterspertile)*meterspertile
    		x1=math.ceil(self.model.aabb.x1/meterspertile)*meterspertile
    		z0=math.floor(self.model.aabb.z0/meterspertile)*meterspertile
    		z1=math.ceil(self.model.aabb.z1/meterspertile)*meterspertile]]
    		x0=math.floor((pos.x-1)/meterspertile)*meterspertile
    		x1=math.ceil((pos.x+1)/meterspertile)*meterspertile
    		z0=math.floor((pos.z-1)/meterspertile)*meterspertile
    		z1=math.ceil((pos.z+1)/meterspertile)*meterspertile
    		cx=x0
    		cz=z0
    		w=x1-x0
    		d=z1-z0
    		patch=CreatePatch(w,d)
    		patchsurf=patch:GetSurface(1)
    		patchsurf:Scale(Vec3(meterspertile*w,1.0,meterspertile*d))
    		patchsurf:Translate(Vec3((cx-Round(w/meterspertile/meterspertile)*meterspertile),0,(cz-Round(d/meterspertile/meterspertile)*meterspertile)))
    	end
    
    	if terrain~=nil then
    		for v=0,patchsurf:CountVertices()-1 do
    			local t=patchsurf:GetVertexPosition(v)
    			local px,pz
    			px = t.x/meterspertile+terrain.resolution/2.0
    			pz = t.z/meterspertile+terrain.resolution/2.0
    			t.y = terrain:GetHeight(px,pz)*terrain.scale.y+0.01
    			patchsurf:SetVertexPosition(v,t)
    		end
    	end
    
    	patch:UpdateLocalAABB()
    	patch:UpdateAABB()
    
    	--calculate texcoords/normals
    	for n=0,patchsurf:CountVertices()-1 do
    		t=patchsurf:GetVertexPosition(n)
    		if terrain~=nil then
    			patchsurf:SetVertexNormal(n,terrain:CalcNormal(t.x,t.z))
    		else
    			patchsurf:SetVertexNormal(n,Vec3(0,1,0))			
    		end			
    	end
    
    	patchsurf:UpdateTangentsAndBinormals()
    
    	if (self.material ~= nil) then
    		patch:Paint(self.material,0)
    	end
    
    	patch:SetParent(self.model,1)
    	self.patch = patch
    end
    
    function object:UnlockKeys()
    	self.super:UnlockKeys()
    end
    
    function object:SetKey(key,value)
    	if key=="material" then
    		self.materialname = value
    		self.material = LoadMaterial("abstract::"..value)
    		if (self.patch ~= nil) then				
    			self.patch:Paint(self.material,0)
    		end
    	else
    		return self.super:SetKey(key,value)
    	end
    end
    
    function object:GetKey(key,value)
    	if key=="material" then
    		return self.materialname
    	else
    		return self.super:GetKey(key,value)
    	end
    end
    
    function object:SetTarget(target,index)
    
    end
    
    function object:UpdateMatrix()
    	self:CreateTerrainAlignedPatch()
    end
    
    function object:ReceiveMessage(message,extra)
    	self.super:ReceiveMessage(message,extra)		
    end
    
    function object:Free(model)
    	self.super:Free()
    end
    
    object:CreateTerrainAlignedPatch()
    
    end
    
    function class:Free()	
    self.super:Free()
    end
    

     

    Images are in the gallery.

×
×
  • Create New...