Giter Club home page Giter Club logo

threejs.miniprogram's Introduction

three.js for wechat miniprogram

该项目的目标是将three.js移植到微信小程序。

使用

下载build目录中的three.weapp.min.js到小程序相应目录。或者你可以构建自己的版本

使用方法可以参考示例threejs-example

兼容性

  • 基本模型
  • OrbitControls
  • TrackballControls
  • TextureLoader
  • GLTFLoader gTLF模型, glb模型加载
  • OBJLoader obj模型加载
  • STLLoader
  • Animation system
  • Raycaster
  • DDSLoader or MTLLoader 待测试

three.js

NPM package Build Size Build Status Dependencies Dev Dependencies Language Grade

JavaScript 3D library

The aim of the project is to create an easy to use, lightweight, 3D library with a default WebGL renderer. The library also provides Canvas 2D, SVG and CSS3D renderers in the examples.

ExamplesDocumentationWikiMigratingQuestionsForumGitterSlack

Usage

Download the minified library and include it in your HTML, or install and import it as a module, Alternatively, see how to build the library yourself.

<script src="js/three.min.js"></script>

This code creates a scene, a camera, and a geometric cube, and it adds the cube to the scene. It then creates a WebGL renderer for the scene and camera, and it adds that viewport to the document.body element. Finally, it animates the cube within the scene for the camera.

var camera, scene, renderer;
var geometry, material, mesh;

init();
animate();

function init() {

	camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
	camera.position.z = 1;

	scene = new THREE.Scene();

	geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
	material = new THREE.MeshNormalMaterial();

	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );

	renderer = new THREE.WebGLRenderer( { antialias: true } );
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );

}

function animate() {

	requestAnimationFrame( animate );

	mesh.rotation.x += 0.01;
	mesh.rotation.y += 0.02;

	renderer.render( scene, camera );

}

If everything went well you should see this.

Change log

Releases

threejs.miniprogram's People

Contributors

06wj avatar aardgoose avatar alteredq avatar arodic avatar bhouston avatar daoshengmu avatar dforrer avatar donmccurdy avatar dubejf avatar fernandojsg avatar gero3 avatar gkjohnson avatar gogoend avatar gregtatum avatar itee avatar kaisalmen avatar linbingquan avatar looeee avatar mrdoob avatar mugen87 avatar paulmasson avatar sole avatar sunag avatar takahirox avatar temdog007 avatar tentone avatar tschw avatar westlangley avatar yomboprime avatar zz85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

threejs.miniprogram's Issues

小程序渲染glb模型后无法响应任何事件

加载基本的cube没有问题,加载obj模型没有问题;但加载glb后,微信开发者工具可以响应事件,真机上无法响应事件,附加载glb模型的代码:

        let GLTFLoader = gLTF(THREE)
        const gltfLoader = new GLTFLoader();
        gltfLoader.load(glbUrl, (gltf) => {
          const item = gltf.scene;
          _this.modelItem = item;
          _this.scene.add(_this.modelItem);
          _this.lights.forEach(light => {
            light.target = _this.modelItem
          })
          _this.inited = true;
          uni.hideLoading();
          
          _this.render();
        }, (res) => {
          console.log('progress res:', res)
        }, (error) => {
          uni.hideLoading();
          console.log('error:', error)
        });

抗锯齿是不是有问题?

在例子里面锯齿非常明显,我自己做了个demo也有很明显的锯齿。
是小程序的问题还是有办法规避呢?

无法使用onProgress监听模型加载进度

gltfLoader.load(url, (gltf) => {
     console.log("strat to load model");
     const root = gltf.scene;
     scene.add(root);
      root.updateMatrixWorld();
      const box = new THREE.Box3().setFromObject(root);
      const boxSize = box.getSize(new THREE.Vector3()).length();
      const boxCenter = box.getCenter(new THREE.Vector3());
      frameArea(boxSize * 0.5, boxSize, boxCenter, camera);
      controls.maxDistance = boxSize * 100;
      controls.target.copy(boxCenter);
      controls.update();
      getChild();
      return "ok"
    },  onProgress=function ( xhr ) {
      console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  },);

项目本机

本机yarn start 启动项目成功
image
但是访问项目失败
image

微信小程序AR基于three.js加载模型纹理失败,显示黑色

//加载cube
const geometry = new THREE.BoxBufferGeometry(0.2, 0.2, 0.2);
/* This doesn't work on iOS because of Uint8ClampedArray bug:
https://developers.weixin.qq.com/community/develop/doc/000408d4f304e038c20e4a00a51400
/
/

const rgbaData = new Uint8ClampedArray([
255,255,255,0,
0,0,0,0,
0,0,0,0,
255,255,255,0
]);*/

const rgbaData = new Uint8Array([
255,255,255,0,
0,0,0,0,
0,0,0,0,
255,255,255,0
]);

const texture = new THREE.DataTexture(rgbaData,2,2);
texture.needsUpdate = true;

const material = new THREE.MeshBasicMaterial({ map: texture });

const mesh = new THREE.Mesh(geometry, material);
mainModel = mesh;
scene.add(mesh);

android device: can not see the mesh when used a texture

I downloaded the example, and test the example on wechat-miniprogram in ios + android device,
when I enter the page named " OrbitControl 立方" , everything is ok if I use iphone , but if I use android phone,I can not see anything, I have try to modify some code in the example, when I change the BoxBufferGeometry to a CubeGeometry without any texture,I can see the mesh, I also add some code seems not important, like add an ambientLight or a pointlight, these operation run evently success.
so I think maybe the probleam is the approach of texture using in android phont.

问一下THREE.global.touchEventHandlerFactory这个方法在哪?

Description of the problem

This form is for three.js bug reports and feature requests only.

This is NOT a help site. Do not ask help questions here.
If you need help, please use the forum or stackoverflow.

Describe the bug or feature request in detail.

Always include a code snippet, screenshots, and any relevant models or textures to help us understand your issue.

Please also include a live example if possible. You can start from these templates:

Three.js version
  • Dev
  • r110
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, ...)

还不太明白这个page里的触摸事件是怎么传递到OrbitControls里的
希望能解答一下:)谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.