@LoopSpace here is my test code. I am trying to make a spotlight beam effect using a 3d cone. Need to add dependencies on your PseudoMesh class and the orbitViewer class (in. Examples). You will see the cone disappears at the same viewer angles for both the invertedNormals and non-inverted normals? Set useTransparency to true get the effect of the light fading with distance (sort of).
-- Test spotlight beam using cone
-- Use this function to perform your initial setup
function setup()
-- Create a new craft scene
scene = craft.scene()
--orbital viewer
scene.camera:add(OrbitViewer, vec3(0,0,0), 400, 0, 2000)
orv=scene.camera:get(OrbitViewer)
--texture for cone for transparency
useTransparency=false
if useTransparency then
coneTexture=image(255,255)
setContext(coneTexture)
for i=1,255 do
for j=1,255 do
mycol=color(46, 218, 240, j)
coneTexture:set(i,j,mycol )
end
end
setContext()
end
coneHeight=1
coneBase=1
local coneMesh = PseudoMesh()
coneMesh:addCylinder({
ends=0,
axis=vec3(0,1,0),
height=coneHeight,
startRadius=coneBase,
endRadius=0,
centre=vec3(0,-coneHeight/2,0),
size=30, --number of facets
})
-- coneMesh:invertNormals()
coneModel= coneMesh:toModel()
--
local coneMesh2 = PseudoMesh()
coneMesh2:addCylinder({
ends=0,
axis=vec3(0,1,0),
height=coneHeight,
startRadius=coneBase,
endRadius=0,
centre=vec3(0,-coneHeight/2,0),
size=30, --number of facets
})
coneMesh2:invertNormals()
coneModel2= coneMesh2:toModel()
cone1=scene:entity()
cone1.model =coneModel
cone1.scale=vec3(1,1,1)*50
cone1.material = craft.material("Materials:Standard")
if useTransparency then
cone1.material.map=coneTexture
cone1.material.diffuse=color(255, 0, 37, 255)
cone1.material.opacity=0.8
cone1.material.blendMode=NORMAL
end
cone2=scene:entity()
cone2.model =coneModel2
cone2.scale=vec3(1,1,1)*50
cone2.material = craft.material("Materials:Standard")
cone2.position=vec3(0,100,0)
if useTransparency then
cone2.material.map=coneTexture
cone2.material.diffuse=color(255, 0, 37, 255)
cone2.material.opacity=0.8
cone2.material.blendMode=NORMAL
end
--]]
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
end
function touched(touch)
orv:touched(touch)
end