1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * Cloner.js
- *
- * @author realor
- */
- import { Solid } from '../core/Solid.js'
- import { Profile } from '../core/Profile.js'
- import { Cord } from '../core/Cord.js'
- import { ObjectBuilder } from './ObjectBuilder.js'
- import * as THREE from '../lib/three.module.js'
- class Cloner extends ObjectBuilder {
- constructor(objectToClone) {
- super()
- this.objectToClone = objectToClone
- this.cloneVisible = true
- }
- traverseDependencies(object, action) {
- if (this.objectToClone) {
- action(this.objectToClone)
- }
- }
- updateReferences(object, update) {
- let newObjectToClone = update(this.objectToClone)
- if (newObjectToClone !== null) {
- this.objectToClone = newObjectToClone
- return true
- }
- return false
- }
- performBuild(object) {
- if (this.objectToClone === undefined) return false
- const clone = object => {
- let clonedObject = object.clone(false)
- if (this.cloneVisible) clonedObject.visible = true
- if (object instanceof Solid || object instanceof Profile || object instanceof Cord) {
- // do not clone children
- } // object is Group or Object3D
- else {
- for (let child of object.children) {
- clonedObject.add(clone(child))
- }
- }
- return clonedObject
- }
- object.clear()
- object.add(clone(this.objectToClone))
- object.updateMatrix()
- return true
- }
- isGeometryBuilder(object) {
- return false
- }
- isChildrenBuilder(object) {
- return true
- }
- copy(source) {
- this.objectToClone = source.objectToClone
- this.cloneVisible = source.cloneVisible
- return this
- }
- }
- ObjectBuilder.addClass(Cloner)
- export { Cloner }
|