【playground】-rotatuib abd scaling(方向)

源码

var createScene = function () {
var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI, Math.PI / 8, 150, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, true); var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); //Creation of 3 boxes and 2 spheres
var box1 = BABYLON.Mesh.CreateBox("Box1", 6.0, scene);
var box2 = BABYLON.Mesh.CreateBox("Box2", 6.0, scene);
var box3 = BABYLON.Mesh.CreateBox("Box3", 6.0, scene);
var box4 = BABYLON.Mesh.CreateBox("Box4", 6.0, scene);
var box5 = BABYLON.Mesh.CreateBox("Box5", 6.0, scene);
var box6 = BABYLON.Mesh.CreateBox("Box6", 6.0, scene);
var box7 = BABYLON.Mesh.CreateBox("Box7", 6.0, scene); //Moving boxes on the x axis
box1.position.x = -20;
box2.position.x = -10;
box3.position.x = 0;
box4.position.x = 15;
box5.position.x = 30;
box6.position.x = 45; //Rotate box around the x axis
box1.rotation.x = Math.PI / 6; //Rotate box around the y axis
box2.rotation.y = Math.PI / 3; //Scaling on the x axis
box4.scaling.x = 2; //Scaling on the y axis
box5.scaling.y = 2; //Scaling on the z axis
box6.scaling.z = 2; //Moving box7 relatively to box1
box7.parent = box1;
box7.position.z = -10; return scene;
}

效果

笔记:

该案例主要讲解物体的方向和定位处理。在原有的声明变量中的定位改为更新新的定位和指定方向

基于X轴的定位更新:box1.position.x = -20;

基于X轴的旋转更新:box1.rotation.x = Math.PI / 6;

基于X轴的拉伸更新:box4.scaling.x = 2;

父子相对定位:box7.parent = box1;box7.position.z = -10;(该部分和用于茶座与杯子的关系处理)


【playground】-materials(纹理)

源码

var createScene = function () {
var scene = new BABYLON.Scene(engine); //Create a light
var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(-60, 60, 80), scene); //Create an Arc Rotate Camera - aimed negative z this time
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, 1.0, 110, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true); //Creation of 6 spheres
var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 9.0, scene);
var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 9.0, scene);//Only two segments
var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 9.0, scene);
var sphere4 = BABYLON.Mesh.CreateSphere("Sphere4", 10.0, 9.0, scene);
var sphere5 = BABYLON.Mesh.CreateSphere("Sphere5", 10.0, 9.0, scene);
var sphere6 = BABYLON.Mesh.CreateSphere("Sphere6", 10.0, 9.0, scene); //Position the spheres
sphere1.position.x = 40;
sphere2.position.x = 25;
sphere3.position.x = 10;
sphere4.position.x = -5;
sphere5.position.x = -20;
sphere6.position.x = -35; //Creation of a plane
var plane = BABYLON.Mesh.CreatePlane("plane", 120, scene);
plane.position.y = -5;
plane.rotation.x = Math.PI / 2; //Creation of a material with wireFrame
var materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
materialSphere1.wireframe = true; //Creation of a red material with alpha
var materialSphere2 = new BABYLON.StandardMaterial("texture2", scene);
materialSphere2.diffuseColor = new BABYLON.Color3(1, 0, 0); //Red
materialSphere2.alpha = 0.3; //Creation of a material with an image texture
var materialSphere3 = new BABYLON.StandardMaterial("texture3", scene);
materialSphere3.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene); //Creation of a material with translated texture
var materialSphere4 = new BABYLON.StandardMaterial("texture4", scene);
materialSphere4.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
materialSphere4.diffuseTexture.vOffset = 0.1;//Vertical offset of 10%
materialSphere4.diffuseTexture.uOffset = 0.4;//Horizontal offset of 40% //Creation of a material with an alpha texture
var materialSphere5 = new BABYLON.StandardMaterial("texture5", scene);
materialSphere5.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
materialSphere5.diffuseTexture.hasAlpha = true;//Has an alpha //Creation of a material and show all the faces
var materialSphere6 = new BABYLON.StandardMaterial("texture6", scene);
materialSphere6.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
materialSphere6.diffuseTexture.hasAlpha = true;//Have an alpha
materialSphere6.backFaceCulling = false;//Show all the faces of the element //Creation of a repeated textured material
var materialPlane = new BABYLON.StandardMaterial("texturePlane", scene);
materialPlane.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
materialPlane.diffuseTexture.uScale = 5.0;//Repeat 5 times on the Vertical Axes
materialPlane.diffuseTexture.vScale = 5.0;//Repeat 5 times on the Horizontal Axes
materialPlane.backFaceCulling = false;//Always show the front and the back of an element //Apply the materials to meshes
sphere1.material = materialSphere1;
sphere2.material = materialSphere2; sphere3.material = materialSphere3;
sphere4.material = materialSphere4; sphere5.material = materialSphere5;
sphere6.material = materialSphere6; plane.material = materialPlane; return scene;
};

效果

笔记:

本案例讲解了6种纹理的处理方式

1.镂空

materialSphere1.wireframe = true

2.纯色+透视

materialSphere2.diffuseColor = new BABYLON.Color3(1, 0, 0); 纯色贴图

materialSphere2.alpha = 0.3;透视

3.jpg贴图

materialSphere3.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);jpg贴图

4.jpg贴图翻转

materialSphere4.diffuseTexture.vOffset = 0.1;垂直翻转
    materialSphere4.diffuseTexture.uOffset = 0.4;水平翻转

5.png贴图

materialSphere5.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
    materialSphere5.diffuseTexture.hasAlpha = true;//适用png的透明(游戏开发的朋友告诉我png比较消耗性能)

6.png贴图翻转

materialSphere6.backFaceCulling = false;//背面贴图显示

另外本案例的镜头比较有意思,可以自由移动切换视角


【playground】-cameras(相机)

源码

var createScene = function () {
var scene = new BABYLON.Scene(engine); // Setup a simple environment
var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 2, 8), scene);
var box1 = BABYLON.Mesh.CreateBox("b1", 1.0, scene);
var box2 = BABYLON.Mesh.CreateBox("b2", 1.0, scene);
box2.position.x = -3;
var box3 = BABYLON.Mesh.CreateBox("b3", 1.0, scene);
box3.position.x = 3; // ArcRotateCamera >> Camera rotating around a 3D point (here Vector zero)
// Parameters : name, alpha, beta, radius, target, scene
var arcCamera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 10, new BABYLON.Vector3(0, 0, 0), scene);
arcCamera.setPosition(new BABYLON.Vector3(0, 0, 50));
arcCamera.target = new BABYLON.Vector3(3, 0, 0); // FreeCamera >> You can move around the world with mouse and keyboard (LEFT/RIGHT/UP/DOWN)
// Parameters : name, position, scene
var freeCamera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 0, 5), scene);
freeCamera.rotation = new BABYLON.Vector3(0, Math.PI, 0); // TouchCamera >> Move in your world with your touch screen (or with your mouse, by drag/drop)
// Parameters : name, position, scene
var touchCamera = new BABYLON.TouchCamera("TouchCamera", new BABYLON.Vector3(0, 0, 10), scene);
touchCamera.rotation = new BABYLON.Vector3(0, Math.PI, 0); //Attach a camera to the scene and the canvas
scene.activeCamera = freeCamera;
freeCamera.attachControl(canvas, true); return scene;
}

效果

笔记:

该案例介绍了3种相机的处理

ArcRotateCamera:以一点为镜头方向点运转,移动相机位置后仍旧镜头朝向目标

FreeCamera:相机固定,可自由变换镜头方向(类似于CS活着时候的视角)

TouchCamera:相机移动,镜头点也跟着移动(类似CS死掉后的上帝视角)

可以更换scene.activeCamera = freeCamera;freeCamera.attachControl(canvas, true);的相机指定,拖动鼠标和键盘上下左右感受不一样的效果

初学WebGL引擎-BabylonJS:第3篇-方向纹理与相机的更多相关文章

  1. 初学WebGL引擎-BabylonJS:第0篇-起因

    学习WebGL的BabylonJS是在一次偶然的情况下进行的,主要为了满足个人对全栈开发的欲望. 言归正传,下面开始简单说说相关过程 WebGL是什么?WebGL是基于html的客户端页面技术,基于h ...

  2. 初学WebGL引擎-BabylonJS:第1篇-基础构造

    继续上篇随笔 步骤如下: 一:http://www.babylonjs.com/中下载源码.获取其中babylon.2.2.js.建立gulp项目

  3. 初学WebGL引擎-BabylonJS:第8篇-阴影网格与活动

    [playground]-shadows(阴影) 源码 var createScene = function () { var scene = new BABYLON.Scene(engine); / ...

  4. 初学WebGL引擎-BabylonJS:第6篇-碰撞交错与挑选

    [playground]-collisions(碰撞) 先贴官方源码(机器翻译版本) var createScene = function () { var scene = new BABYLON.S ...

  5. 初学WebGL引擎-BabylonJS:第4篇-灯光动画与丛林场景

    前几章接触的案例都是接近静态的,由这张开始开始接触大量动态的内容,包括 球体灯光,变动的形体,以及一个虚拟的丛林场景 下章我会试着结合1-9案例的内容做出一个demo出来 [playground]-l ...

  6. 初学WebGL引擎-BabylonJS:第2篇-基础模型体验

    此次学习进度会比之前快很多,有了合适的学习方法后也就会有更多的乐趣产生了. 接上一章代码 上章代码 <!DOCTYPE html> <html> <head> &l ...

  7. [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析

    [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析 标签: webkit内核JavaScriptCore 2015-03-26 23:26 2285 ...

  8. CROW-5 WEB APP引擎商业计划书(HTML5方向)-微信网页版微信公众平台登录-水仙谷

    CROW-5 WEB APP引擎商业计划书(HTML5方向)-微信网页版微信公众平台登录-水仙谷 CROW-5 WEB APP引擎商业计划书(HTML5方向)

  9. 用基于WebGL的BabylonJS来共享你的3D扫描模型

    转自:http://www.geekfan.net/6578/ 用基于WebGL的BabylonJS来共享你的3D扫描模型 杰克祥子 2014 年 2 月 26 日 0 条评论 标签:3D扫描 , B ...

随机推荐

  1. LeetCode 89,因为题目晦涩而被点了1500+反对的搜索问题

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第55篇文章,我们一起来看看LeetCode中的第89题 Gray Code(格雷码). 这题的官方难度是Medi ...

  2. .NET和.NET Core Web APi FormData多文件上传对比

    前言 最近因维护.NET和.NET Core项目用到文件上传功能,虽说也做过,但是没做过什么对比,借此将二者利用Ajax通过FormData上传文件做一个总结,通过视图提交表单太简单,这里不做阐述,希 ...

  3. 2020-05-31:假如Redis里面有1亿个key,其中有10w个key是以某个固定的已知的前缀开头的,如何将它们全部找出来?

    福哥答案2020-05-31: 使用keys指令可以扫出指定模式的key列表.对方接着追问:如果这个redis正在给线上的业务提供服务,那使用keys指令会有什么问题?这个时候你要回答redis关键的 ...

  4. C#LeetCode刷题-记忆化

    记忆化篇 # 题名 刷题 通过率 难度 329 矩阵中的最长递增路径   31.0% 困难

  5. Docker服务开放了这个端口,服务器分分钟变肉机

    之前有很多朋友提过,当使用docker-maven-plugin打包SpringBoot应用的Docker镜像时,服务器需要开放2375端口.由于开放了端口没有做任何安全保护,会引起安全漏洞,被人入侵 ...

  6. K8S(11)配置中心实战-单环境交付apollo三组件

    k8s配置中心实战-交付apollo三组件 目录 k8s配置中心实战-交付apollo三组件 1 apollo简单说明 1.1 apollo最简架构图: 1.2 apollo组件部署关系 2 为app ...

  7. mysql-5.7.xx在lcentos7下的安装以及mysql在windows以及linux上的性能差异

    前言: 在centos上安装mysql,整整折腾了将近一天,因为是第一次安装,的确是踩了不少坑,这里详细记录下来,方便各位有同样需求的小伙伴参考. 该选择什么版本? mysql5.7有很多小版本,但是 ...

  8. 如何在 asp.net core 的中间件中返回具体的页面

    前言 在 asp.net core 中,存在着中间件这一概念,在中间件中,我们可以比过滤器更早的介入到 http 请求管道,从而实现对每一次的 http 请求.响应做切面处理,从而实现一些特殊的功能 ...

  9. Excel 提取年月日①

    问题场景 从任务数据表中比较所有任务的预计完成时间和实际完成时间,来判断该任务是逾期还是按期完成了,根据实际场景是不需要考虑时分秒,只需对比该任务预计完成和实际完成的年月日. 可通过提取年月日用函数进 ...

  10. 精讲RestTemplate第10篇-使用代理作为跳板发送请求

    本文是精讲RestTemplate第10篇,前篇的blog访问地址如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层 ...