浏览代码

CSS3DSprite with parent scale (#22235)

* CSS3DSprite with parent scale

CSS3DSprite seems to ignore parent scale completely; this seems to fix it, but I don't know if there are better / cleaner solutions

* CSS3DSprite set scale from world matrix

use the world matrix of the same object to fix scale

* Fix getWorldMatrix deprecation warning

Put a target for getWorldMatrix

* Reusing Vectors and calling decompose directly

Vectors are declared at the top and reused; getWorldScale is replaced by direct use of decompose in order to reuse vectors

* use decompose to also set position

call setPosition with the result from decompose
GiuseppeRaso 3 年之前
父节点
当前提交
686e5deb9d
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      examples/jsm/renderers/CSS3DRenderer.js

+ 10 - 3
examples/jsm/renderers/CSS3DRenderer.js

@@ -1,12 +1,18 @@
 import {
 	Matrix4,
-	Object3D
+	Object3D,
+	Quaternion,
+	Vector3
 } from '../../../build/three.module.js';
 
 /**
  * Based on http://www.emagix.net/academic/mscs-project/item/camera-sync-with-css3-and-webgl-threejs
  */
 
+const _position = new Vector3();
+const _quaternion = new Quaternion();
+const _scale = new Vector3();
+
 class CSS3DObject extends Object3D {
 
 	constructor( element ) {
@@ -245,8 +251,9 @@ class CSS3DRenderer {
 
 					if ( object.rotation2D !== 0 ) _matrix.multiply( _matrix2.makeRotationZ( object.rotation2D ) );
 
-					_matrix.copyPosition( object.matrixWorld );
-					_matrix.scale( object.scale );
+					object.matrixWorld.decompose( _position, _quaternion, _scale );
+					_matrix.setPosition( _position );
+					_matrix.scale( _scale );
 
 					_matrix.elements[ 3 ] = 0;
 					_matrix.elements[ 7 ] = 0;