我在不同 div 元素中的同一视图中有多个实例时遇到问题。当我尝试初始化它们时,无论我将它们放入什么顺序,都只会出现两个元素中的第二个。
这是我的观点的代码。
var BodyShapeView = Backbone.View.extend({
thingiview: null,
scene: null,
renderer: null,
model: null,
mouseX: 0,
mouseY: 0,
events:{
'click button#front' : 'front',
'click button#diag' : 'diag',
'click button#in' : 'zoomIn',
'click button#out' : 'zoomOut',
'click button#on' : 'rotateOn',
'click button#off' : 'rotateOff',
'click button#wireframeOn' : 'wireOn',
'click button#wireframeOff' : 'wireOff',
'click button#distance' : 'dijkstra'
},
initialize: function(name){
_.bindAll(this, 'render', 'animate');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 15, 400 / 700, 1, 4000 );
camera.position.z = 3;
scene.add( camera );
camera.position.y = -5;
var ambient = new THREE.AmbientLight( 0x202020 );
scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.75 );
directionalLight.position.set( 0, 0, 1 );
scene.add( directionalLight );
var pointLight = new THREE.PointLight( 0xffffff, 5, 29 );
pointLight.position.set( 0, -25, 10 );
scene.add( pointLight );
var loader = new THREE.OBJLoader();
loader.load( "img/originalMeanModel.obj", function ( object ) {
object.children[0].geometry.computeFaceNormals();
var geometry = object.children[0].geometry;
console.log(geometry);
THREE.GeometryUtils.center(geometry);
geometry.dynamic = true;
var material = new THREE.MeshLambertMaterial({color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors });
mesh = new THREE.Mesh(geometry, material);
model = mesh;
// model = object;
scene.add( model );
} );
// RENDERER
renderer = new THREE.WebGLRenderer();
renderer.setSize( 400, 700 );
$(this.el).find('.obj').append( renderer.domElement );
this.animate();
},
这是我创建实例的方式
var morphableBody = new BodyShapeView({ el: $("#morphable-body") });
var bodyShapeView = new BodyShapeView({ el: $("#mean-body") });
任何帮助将非常感激。
提前致谢。