GithubHelp home page GithubHelp logo

pixiv / three-vrm Goto Github PK

View Code? Open in Web Editor NEW
1.1K 86.0 99.0 115.09 MB

Use VRM on Three.js

License: MIT License

TypeScript 65.84% GLSL 4.81% JavaScript 6.91% HTML 22.32% Shell 0.12%
gltf threejs vrm 3d avatar webgl

three-vrm's Introduction

@pixiv/three-vrm

@pixiv/three-vrm on npm

Use VRM on three.js

three-vrm

GitHub Repository

Examples

Documentations

API Reference

v1

three-vrm v1 has been released!

three-vrm v1 supports VRM1.0, which is a new version of VRM format (the previous version of VRM is also supported, don't worry!). It also adopts the GLTFLoader plugin system which is a relatively new feature of GLTFLoader.

There are a lot of breaking changes! See the migration guide for more info.

How to Use

from HTML

You will need:

You can import all of them via CDN. See the example below.

Code like this:

<script type="importmap">
  {
    "imports": {
      "three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
      "three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/",
      "@pixiv/three-vrm": "three-vrm.module.js"
    }
  }
</script>

<script type="module">
  import * as THREE from 'three';
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  import { VRMLoaderPlugin } from '@pixiv/three-vrm';

  const scene = new THREE.Scene();

  const loader = new GLTFLoader();

  // Install GLTFLoader plugin
  loader.register((parser) => {
    return new VRMLoaderPlugin(parser);
  });

  loader.load(
    // URL of the VRM you want to load
    '/models/VRM1_Constraint_Twist_Sample.vrm',

    // called when the resource is loaded
    (gltf) => {
      // retrieve a VRM instance from gltf
      const vrm = gltf.userData.vrm;

      // add the loaded vrm to the scene
      scene.add(vrm.scene);

      // deal with vrm features
      console.log(vrm);
    },

    // called while loading is progressing
    (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),

    // called when loading has errors
    (error) => console.error(error),
  );
</script>

via npm

Install three and @pixiv/three-vrm :

npm install three @pixiv/three-vrm

Code like this:

import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { VRMLoaderPlugin } from '@pixiv/three-vrm';

const scene = new THREE.Scene();

const loader = new GLTFLoader();

// Install GLTFLoader plugin
loader.register((parser) => {
  return new VRMLoaderPlugin(parser);
});

loader.load(
  // URL of the VRM you want to load
  '/models/VRM1_Constraint_Twist_Sample.vrm',

  // called when the resource is loaded
  (gltf) => {
    // retrieve a VRM instance from gltf
    const vrm = gltf.userData.vrm;

    // add the loaded vrm to the scene
    scene.add(vrm.scene);

    // deal with vrm features
    console.log(vrm);
  },

  // called while loading is progressing
  (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),

  // called when loading has errors
  (error) => console.error(error),
);

Contributing

See: CONTRIBUTING.md

LICENSE

MIT

three-vrm's People

Contributors

0b5vr avatar actions-user avatar alaricbaraou avatar dependabot-preview[bot] avatar dependabot[bot] avatar fogrexon avatar jlchntoz avatar ke456-png avatar keshigom avatar kuyuri-pixinter avatar marwie avatar mattrossman avatar mtblue81 avatar saitolume avatar saturday06 avatar silvea12 avatar sue445 avatar takanakahiko avatar tfuru avatar yomotsu avatar yoshidan avatar you74674 avatar yue4u 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  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

three-vrm's Issues

Dependabot couldn't find a package.json for this project

Dependabot couldn't find a package.json for this project.

Dependabot requires a package.json to evaluate your project's current JavaScript dependencies. It had expected to find one at the path: /playground/package.json.

If this isn't a JavaScript project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

VRMSpringBoneManager: is `VRMSpringBoneManager.createSpringBone` required?

protected createSpringBone(
gltf: GLTF,
bone: THREE.Object3D,
hitRadius: number,
stiffiness: number,
gravityDir: THREE.Vector3,
gravityPower: number,
dragForce: number,
colliders: THREE.Mesh[] = [],
): VRMSpringBone {
return new VRMSpringBone(bone, hitRadius, stiffiness, gravityDir, gravityPower, dragForce, colliders);
}

VRMSpringBone のコンストラクタに、渡された引数をそのまま渡しているようですが、
これは直接 VRMSpringBone を作るのではだめなのでしたっけ?

Install tests

スナップショットやりたいときはヘッドレスの gl 使えば良さそうだけど
CIで回すのがちょっと大変そうです。
Dockerイメージ作るのがやや面倒、ただの node イメージだとできない……

前に一度CircleCIで回したことがあるので、以下を参照ください:

https://github.com/FMS-Cat/glcat-ts

Dependabot couldn't find a package.json for this project

Dependabot couldn't find a package.json for this project.

Dependabot requires a package.json to evaluate your project's current JavaScript dependencies. It had expected to find one at the path: /playground/package.json.

If this isn't a JavaScript project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

`README.md` npm example's module usage is confusing

The module usage of the "npm" example in README.md is confusing. The example has the following import statements:

import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { VRM } from '@pixiv/three-vrm';

However, GLTFLoader and VRM is apparently referred as THREE.GLTFLoader and THREE.VRM. Then what does the literal GLTFLoader and VRM does?

Also, it does not tell how import should be interpreted. It matters because there are number of options for interpretation (e.g. the "babel" transpiler, webpack, and Node.js's ESM.)

uploading boneTextures is a bottleneck

shino.vrm において、1フレーム内で最も負荷の高い処理が texImage2D (テクスチャのアップロード)だった。
ここでアップロードしているテクスチャは、boneTextureらしい。
メッシュごとにボーンに対応するテクスチャをアップロードしなければならないため、
テクスチャのアップロードが1フレームあたりメッシュ枚数分発生する。

image

改善のため、Three.jsにコントリビューションしなければならない可能性も大いにアリ?

VRMFirstPerson: Discussion about `FirstPersonCameraLayerSetting`

export interface FirstPersonCameraLayerSetting {
firstPersonOnlyLayer?: number;
thirdPersonOnlyLayer?: number;
}

FirstPersonCameraLayerSetting は、 VRMFirstPerson.setup を叩く際に
FirstPersonOnly / ThirdPersonOnly それぞれに割り当たるレイヤーを指定するためのインタフェースですが、
内部的にこれが特に FirstPersonCameraLayerSetting として定義されていない以上、
これは特にインタフェース化されている必要がないように感じました。

もしくは、
VRMFirstPerson.DEFAULT_FIRSTPERSON_ONLY_LAYER / VRMFirstPerson.DEFAULT_THIRDPERSON_ONLY_LAYER および
VRMFirstPerson._firstPersonOnlyLayer / VRMFirstPerson._thirdPersonOnlyLayer
当該インタフェースを利用する方向に倒しても良いと思います。

UniVRMとのAPIの近さを考慮すると悩みどころですが、どちらにもインタフェースを採用する方に思い切ってしまってもいいかも……?

VRMFirstPerson: getFirstPersonBonePosition -> getFirstPersonPosition

getFirstPersonBonePosition は、UniVRMには無いメソッドですが、FirstPersonの位置を取得する上でたいへん有用となる関数です。

public getFirstPersonBonePosition(v3: THREE.Vector3): THREE.Vector3 {
// UniVRM#VRMFirstPersonEditor
// var worldOffset = head.localToWorldMatrix.MultiplyPoint(component.FirstPersonOffset);
const offset = this._firstPersonBoneOffset;
const v4 = new THREE.Vector4(offset.x, offset.y, offset.z, 1.0);
v4.applyMatrix4(this._firstPersonBone.matrixWorld);
return v3.set(v4.x, v4.y, v4.z);
}

これは、ボーンの位置というよりかはoffsetを含めたFirstPersonの位置を返すものであるため、APIとしても getFirstPersonPosition のほうが適切かと思います。

GLTFLoaderの管理場所

THREEのGLTFLoaderをforkして修正しているGLTFLoaderの管理場所

  • exampleに移動
  • three-vrm-loaderとして別レポで管理
  • three本体にVRMLoaderとしてマージ?

Dependabot couldn't find a package.json for this project

Dependabot couldn't find a package.json for this project.

Dependabot requires a package.json to evaluate your project's current JavaScript dependencies. It had expected to find one at the path: /playground/package.json.

If this isn't a JavaScript project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

Warning: "THREE.ShaderMaterial: 'mToonVersion' is not a property of this material."

https://pixiv.github.io/three-vrm/examples/basic.html emits following warning message:

three.js:8628 THREE.ShaderMaterial: 'mToonVersion' is not a property of this material.
setValues @ three.js:8628
MToonMaterial @ MToonMaterial.ts:243
(anonymous) @ VRMMaterialImporter.ts:161
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
fulfilled @ MToonMaterial.ts:96
Promise.then (async)
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.__awaiter @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.VRMMaterialImporter.createVRMMaterials @ VRMMaterialImporter.ts:135
(anonymous) @ VRMMaterialImporter.ts:92
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.__awaiter @ MToonMaterial.ts:96
(anonymous) @ VRMMaterialImporter.ts:66
(anonymous) @ VRMMaterialImporter.ts:66
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.__awaiter @ MToonMaterial.ts:96
(anonymous) @ VRMMaterialImporter.ts:62
(anonymous) @ VRMMaterialImporter.ts:62
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
fulfilled @ MToonMaterial.ts:96
Promise.then (async)
step @ MToonMaterial.ts:96
(anonymous) @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.__awaiter @ MToonMaterial.ts:96
__three_vrm__../src/vrm/material/VRMMaterialImporter.ts.VRMMaterialImporter.convertGLTFMaterials @ VRMMaterialImporter.ts:46
(anonymous) @ VRMImporter.ts:71
step @ VRM.ts:29
(anonymous) @ VRM.ts:29
(anonymous) @ VRM.ts:29
__three_vrm__../src/vrm/VRMImporter.ts.__awaiter @ VRM.ts:29
__three_vrm__../src/vrm/VRMImporter.ts.VRMImporter.import @ VRMImporter.ts:51
(anonymous) @ VRM.ts:54
step @ index.ts:1
(anonymous) @ index.ts:1
(anonymous) @ index.ts:1
__three_vrm__../src/vrm/VRM.ts.__awaiter @ index.ts:1
__three_vrm__../src/vrm/VRM.ts.VRM.from @ VRM.ts:52
(anonymous) @ basic.html:63
(anonymous) @ GLTFLoader.js:84
(anonymous) @ GLTFLoader.js:1591
Promise.then (async)
THREE.GLTFLoader.GLTFParser.parse @ GLTFLoader.js:1575
parse @ GLTFLoader.js:235
(anonymous) @ GLTFLoader.js:82
(anonymous) @ three.js:34856
load (async)
load @ three.js:34836
load @ GLTFLoader.js:78
(anonymous) @ basic.html:54

error in using Angularjs

Angularjs(Typescript) 内で使用すると以下のようなエラーが出ます。

ERROR in node_modules/@pixiv/three-vrm/types/vrm/VRM.d.ts(20,29): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/VRMImporter.d.ts(25,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/blendshape/VRMBlendShapeImporter.d.ts(4,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/debug/VRMDebug.d.ts(6,29): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/debug/VRMSpringBoneImporterDebug.d.ts(6,45): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/firstperson/VRMFirstPersonImporter.d.ts(5,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/humanoid/VRMHumanoidImporter.d.ts(4,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/lookat/VRMLookAtHead.d.ts(5,35): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pixiv/three-vrm/types/vrm/lookat/VRMLookAtImporter.d.ts(9,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/material/VRMMaterialImporter.d.ts(11,38): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/material/VRMMaterialImporter.d.ts(12,100): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/springbone/VRMSpringBoneImporter.d.ts(5,24): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.
node_modules/@pixiv/three-vrm/types/vrm/springbone/VRMSpringBoneImporter.d.ts(7,45): error TS2694: Namespace '"/node_modules/three/src/Three"' has no exported member 'GLTF'.

調べた限りですと、ライブラリ内で THREE.GLTF を使用している場所があり、 Typescript内(@types/three) ではこの部分が読み込めていないようです。
(もしかしたら、ライブラリ内のthree.jsのバージョンを上げれば直るかもしれないですが)
ここの部分の修正とかってお願いできますでしょうか?(すでに修正済みでしたらすみません。)
お願いします。

VRMFirstPerson: FirstPersonBone and FirstPersonBoneOffset can be public mutable members

現在、どちらも private readonly のメンバとして実装されており、それぞれ get*** メソッドで取得可能となっていますが、
オリジナルのUniVRMではこれらは public なメンバとなっています。
特に途中で変更されることに実装上の問題が無いならば、これらのメンバは公開してしまっても良いかなと思います。

How about let spring bone features being disableable?

パフォーマンスや用途によっては、揺れものを無効化したいような状況がある気がします。
それを可能とするAPIが VRMSpringBoneManager もしくは VRM にあっても良いかなと思いました。

playground error / should VRMLookAtHead have original Head ?

VRMLookAtHeadからgetHeadPositionが亡くなっており、playgroundでエラーが発生していました。firstPerson.getFirstPersonWorldPosition(_v3B);に置き換えて修正してもよいのですが、
UniVRMだと、VRMLookAtHeadのHeadとVRMFirstPersonのfirstPersonBoneは独立した扱いになっており、three-vrmの方もVRMLookAtHeadはHeadをHumanBodyBonesからとるように戻した方がよいのかと思ったのですが、いかがでしょうか。

以下UniVRMのVRMLookAtHead

 void Awake()
        {
            var animator = GetComponent<Animator>();
            if (animator == null)
            {
                Debug.LogWarning("animator is not found");
                return;
            }

            var head = animator.GetBoneTransform(HumanBodyBones.Head);
            if (head == null)
            {
                Debug.LogWarning("head is not found");
                return;
            }

            Head = head;
        }

MToon: Support _MToonVersion

#128 で一旦握りつぶしましたが、MToonのバージョン間の差異がわかれば、このプロパティにはちゃんと対応しておきたいですね。

MToon: Artifact on VRoid models

image

髪の断面にアーティファクト。MatCapを見るとわかりやすい。
たしかUVのdeltaが無いなどで前にも苦しんだ箇所。

全exampleがマージされたらCSSを書く

必要なCSSは

body {margin: 0}
canvas{ display: block }

の2行だけでよさそうなので、exampleは全体的にそうしたいと思います。

  • body にはデフォルトで 8px のマージンがついているので、このままだと余白ができる
  • canvas はデフォルトだと inline-block なので、「行」をつくる。その結果、ディセンダの空白ができてしまう。blockにすると行を作らなくなり、空白がなくなる。
  • 上記2つ以外の指定は不要なはず

Dependabot couldn't find a package.json for this project

Dependabot couldn't find a package.json for this project.

Dependabot requires a package.json to evaluate your project's current JavaScript dependencies. It had expected to find one at the path: /playground/package.json.

If this isn't a JavaScript project, or if it is a library, you may wish to disable updates for it in the .dependabot/config.yml file in this repo.

View the update logs.

THREE 104以上でMToon使ってるとエラーが発生

MToonのuniformにlightProbeが存在しないので、three.js#initiMaterialが実行されるところでエラーとなる。(ビルドはできるが実行時エラー)

v103のthree.js#initMaterial

24211     uniforms.ambientLightColor.value = lights.state.ambient;
24212     uniforms.directionalLights.value = lights.state.directional;

v106のthree.js#initMaterial

24567     uniforms.ambientLightColor.value = lights.state.ambient;
24568     uniforms.lightProbe.value = lights.state.probe;   <- ここでuniforms.lightProbeがundefined
24569     uniforms.directionalLights.value = lights.state.directional; 

gh-pages

  • dist / examples / docs が入っていてほしい
  • postpublish で自動で叩いてくれるととても嬉しい

Normals should be generated on user end when normal does not exist on the buffer

お問い合わせ経由で報告いただきました。

以下の理由から、クライアントサイドでの法線生成を実装したほうが良さそうです:

Three.jsのBufferGeometryには、幸い computeVertexNormals があるため、これを使えば簡単にできそうです。
どの状況下で法線を生成すべきかをマテリアルのインポート時に見極め、必要であれば法線を生成する、という形の実装とするのが良さそうでしょうか。
https://threejs.org/docs/#api/en/core/BufferGeometry.computeVertexNormals

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.