Fancy3D引擎sample学习(B)
1、blender-additive
渲染一个茶壶的变色过程
_Blender:颜色混合器,功能包括混色、高亮、加色和灰化等。
additive(_Color.1, _Color2, time)
在time时间内从颜色1变化到颜色2,返回_Blender
_rd:useBlender(b1)
teapot:drawMesh()
_rd:popBlender()
PS:前面有过_rd:useLight(a)和_rd.bgColor的过程,最后的效果会出现一个颜色混合的效果,不只是蓝色变到黄色。
1 _dofile('cameracontrol.lua') 2 teapot = _mf:createTeapot() 3 _rd.camera.eye = _Vector3.new(5, 5, 5) 4 a = _AmbientLight.new() 5 a.color = _Color.Green 6 _rd:useLight(a) 7 b1 = _Blender.new() 8 b1:additive(_Color.Blue, _Color.Yellow, 3000) 9 _rd.bgColor=_Color.Red 10 11 _app:onIdle(function(e) 12 _rd:drawAxis(50) 13 _rd:useBlender(b1) 14 teapot:drawMesh() 15 _rd:popBlender() 16 end)
2、blender-gray
b:gray(from, to, duration)
在duration内,从from灰化度变化到to的灰化度,取值0~1
3、blender-highlight
b:highlight(_Color.1, _Color.2, time)
在time时间内高亮颜色1变化到高亮颜色2
4、blender-paint
b:paint(_Color.1, number)
根据number的不同取值,对贴图的不同区域进行着色。。但是API没看懂。
5、brush-texture
通过鼠标事件,在地形中实现刷子的功能
_Terrain类中的方法(API还没有描述)
sen.terrain:brushTexture(刷子类型, picked.x, picked.y, 刷子范围, 透明度, 刷子作用后的图片)
例:image = _Image.new('brush.tga')
tex = _Image.new('texture.jpg')
sen.terrain:brushTexture(image, p.x, p.y, 50, 0.5, tex)
PS:程序加入了cameracontrol.lua的模板
1 _dofile('cameracontrol.lua') 2 _sys:addPath('res') 3 4 sen = _Scene.new('terrainTex.sen') 5 image = _Image.new('brush.tga') 6 tex = _Image.new('texture03.jpg') 7 8 pl = _PointLight.new( ); 9 pl.color = 0xffff00 10 pl.position = _Vector3.new( 0, 0, 750 ) 11 pl.range = 800 12 pl.power = 10 13 pl.terrain = sen.terrain 14 sen.graData:addLight(pl) 15 16 mouse = {mousex = 0, mousey = 0} 17 _app:onMouseMove(function(x, y) 18 if _sys:isKeyDown(_System.MouseMiddle) then 19 if _sys:isKeyDown(_System.KeyAlt) then 20 _rd.camera:movePhi(-(mouse.mousex - x) * 0.005) 21 _rd.camera:moveTheta(-(mouse.mousey - y) * 0.005) 22 else 23 local dir = _Vector3.sub(_rd.camera.look, _rd.camera.eye) 24 local vx = _Vector3.cross(dir, _rd.camera.up):normalize() 25 local vy = _Vector3.cross(dir, vx):normalize() 26 local nearx = _Vector3.mul(vx, -(mouse.mousex - x) * 0.001) 27 local neary = _Vector3.mul(vy, (mouse.mousey - y) * 0.001) 28 local movex = _Vector3.mul(nearx, dir:magnitude() / _rd.camera.viewNear) 29 local movey = _Vector3.mul(neary, dir:magnitude() / _rd.camera.viewNear) 30 local move = _Vector3.add(movex , movey) 31 _rd.camera:moveEye(_rd.camera.eye.x + move.x, _rd.camera.eye.y + move.y, _rd.camera.eye.z + move.z) 32 _rd.camera:moveLook(_rd.camera.look.x + move.x, _rd.camera.look.y + move.y, _rd.camera.look.z + move.z) 33 end 34 elseif _sys:isKeyDown(_System.MouseLeft) then 35 local p = sen:pick(_rd:buildRay(x, y)) 36 if p then 37 sen.terrain:brushTexture(image, p.x, p.y, 50, 0.5, tex) 38 end 39 end 40 41 mouse.mousex = x 42 mouse.mousey = y 43 end) 44 45 sen:onRender(function(node) 46 if node.terrain then 47 node.terrain:draw() 48 else 49 node.mesh:drawMesh() 50 end 51 end) 52 53 _app:onIdle(function(e) 54 sen:render() 55 end)

浙公网安备 33010602011771号