star_mod_renderer
Advanced tools
Comparing version 1.0.51 to 1.0.52
@@ -62,3 +62,3 @@ import * as THREE from 'star_mod_custom_three'; | ||
delta.applyQuaternion(object.quaternion); | ||
delta.multiplyScalar(distance * 4); | ||
delta.multiplyScalar(distance * 2.8); | ||
@@ -68,3 +68,2 @@ object.position.copy(center).add(delta); | ||
scope.dispatchEvent(changeEvent); | ||
}; | ||
@@ -71,0 +70,0 @@ |
@@ -270,2 +270,22 @@ import * as THREE from 'star_mod_custom_three'; | ||
// 默认地板模型 | ||
export const defaultFloorModel = { | ||
fbx: { | ||
domesticPath: 'https://mod-img.westar.qq.com/mod/modOfficial/1696502077_默认地基.FBX', | ||
// abroadPath: '' | ||
}, | ||
dTGA: { | ||
domesticPath: 'https://mod-img.westar.qq.com/mod/modOfficial/1696502125_默认地基D.TGA', | ||
// abroadPath: '' | ||
}, | ||
nTGA: { | ||
domesticPath: 'https://mod-img.westar.qq.com/mod/modOfficial/1696502161_默认地基N.TGA', | ||
// abroadPath: '' | ||
}, | ||
ormeTGA: { | ||
domesticPath: 'https://mod-img.westar.qq.com/mod/modOfficial/1696502213_默认地基O.TGA', | ||
// abroadPath: '' | ||
} | ||
} | ||
// 玻璃、男性头部皮肤、男性身体皮肤、女性头部皮肤、女性身体皮肤 | ||
@@ -272,0 +292,0 @@ export const specificMaterial = { |
@@ -59,3 +59,3 @@ import { FBXLoader } from "./FBXLoader"; | ||
if (type === "tga" && url.endsWith('.tga')) { | ||
if (type === "tga" && (url.toLocaleLowerCase().endsWith('.tga'))) { | ||
const res = await loadTGAFile(url); | ||
@@ -65,3 +65,3 @@ return res; | ||
if(type === 'tga' && (url.endsWith('.png') || url.endsWith('.jpg')) ) { | ||
if(type === 'tga' && (url.toLocaleLowerCase().endsWith('.png') || url.toLocaleLowerCase().endsWith('.jpg')) ) { | ||
const res = await loadPNGFile(url); | ||
@@ -68,0 +68,0 @@ return res; |
@@ -51,6 +51,6 @@ import * as THREE from 'star_mod_custom_three'; | ||
child.frustumCulled = false; | ||
if (child.geometry.attributes && child.geometry.attributes.uv && child.geometry.attributes.uv) { | ||
var uvs = child.geometry.attributes.uv.array; | ||
child.geometry.setAttribute('uv2', new THREE.BufferAttribute(uvs, 2)); | ||
} | ||
// if (child.geometry.attributes && child.geometry.attributes.uv && child.geometry.attributes.uv2) { | ||
// var uvs = child.geometry.attributes.uv.array; | ||
// child.geometry.setAttribute('uv2', new THREE.BufferAttribute(uvs, 2)); | ||
// } | ||
@@ -65,2 +65,10 @@ child.material = this.assembleStandardModelMaterial(child.material); | ||
setModelVisibility(visible) { | ||
this.model.traverse(child => { | ||
if (child.isMesh) { | ||
child.visible = visible; | ||
} | ||
}); | ||
} | ||
removeMutationSection(model) { | ||
@@ -67,0 +75,0 @@ const sectionList = []; |
@@ -174,4 +174,8 @@ import * as THREE from 'star_mod_custom_three'; | ||
setEnvMap(any): void; | ||
start(): void; | ||
changeExtraModelsVisibility(any): void; | ||
getCurrPreviewStoreData(): any; | ||
@@ -178,0 +182,0 @@ |
{ | ||
"name": "star_mod_renderer", | ||
"version": "1.0.51", | ||
"version": "1.0.52", | ||
"description": "star mod project render auxiliary", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -719,7 +719,5 @@ /** | ||
if (!target) return; | ||
if (target.isGrid) return; | ||
if (target === this.camera || target === this.scene) return; | ||
if (target === this.ambientLight || this.directionalLights.includes(target)) | ||
if (target.isGrid || target === this.camera || target === this.scene || target === this.ambientLight || this.directionalLights.includes(target)) { | ||
return; | ||
} | ||
this.cameraControls.focus(target); | ||
@@ -784,3 +782,3 @@ | ||
const img = new Image(); | ||
let imgData = this.renderer.domElement.toDataURL("image/jpeg"); | ||
let imgData = this.renderer.domElement.toDataURL(); | ||
img.src = imgData; | ||
@@ -787,0 +785,0 @@ |
164
render.js
@@ -81,3 +81,4 @@ /** | ||
// defaultSkeletonData, | ||
defaultModelAnimation | ||
defaultModelAnimation, | ||
defaultFloorModel | ||
} from "./default"; | ||
@@ -350,3 +351,2 @@ import { ModelProcessor } from "./helper/modelHelper/index"; | ||
// TODO: 默认动作 | ||
if (fashionConfig.animations) { | ||
@@ -408,2 +408,49 @@ const loadDefaultAnimations = async () => { | ||
} | ||
} else { | ||
// 如果是普通单品模型的话,加载地板 | ||
const floorAuxiliary = new MainModelAuxiliary( | ||
defaultFloorModel.fbx.domesticPath | ||
); | ||
const floorModelOriginalData = await floorAuxiliary.loadModel(); | ||
const floorModelRender = new ModelProcessor(floorModelOriginalData); | ||
this.extraModels.push(floorModelRender); | ||
this.auxiliaryModels.floor = floorModelRender; | ||
const loadFloorModelChannelTexture = async () => { | ||
const loaderList = []; | ||
if (defaultFloorModel.dTGA.domesticPath) { | ||
loaderList.push(loadFile({ | ||
url: defaultFloorModel.dTGA.domesticPath, | ||
type: 'tga' | ||
})) | ||
} | ||
if (defaultFloorModel.nTGA.domesticPath) { | ||
loaderList.push(loadFile({ | ||
url: defaultFloorModel.nTGA.domesticPath, | ||
type: 'tga' | ||
})) | ||
} | ||
// if (defaultFloorModel.ormeTGA.domesticPath) { | ||
// loaderList.push(loadFile({ | ||
// url: defaultFloorModel.ormeTGA.domesticPath, | ||
// type: 'tga' | ||
// })) | ||
// } | ||
if (loaderList.length) { | ||
const files = await Promise.all(loaderList); | ||
files[0].wrapS = THREE.RepeatWrapping; | ||
files[0].wrapT = THREE.RepeatWrapping; | ||
files[1].wrapS = THREE.RepeatWrapping; | ||
files[1].wrapT = THREE.RepeatWrapping; | ||
// files[2].wrapS = THREE.RepeatWrapping; | ||
// files[2].wrapT = THREE.RepeatWrapping; | ||
floorModelRender.updateModelMaterialTexture(0, { | ||
diffuseTexture: files[0], | ||
normalTexture: files[1], | ||
// ormeTexture: files[2], | ||
}); | ||
} | ||
}; | ||
this.modelsLoader.push( | ||
loadFloorModelChannelTexture() | ||
); | ||
} | ||
@@ -431,9 +478,3 @@ | ||
getEnvMapByName(envMap, processEnv).then((environment) => { | ||
if (environment) { | ||
this.setSceneEnvironment(environment.data); | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
this.extraModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}); | ||
} | ||
this.setEnvMap(environment); | ||
resolve(); | ||
@@ -645,11 +686,3 @@ }); | ||
getEnvMapByName(envMap, processEnv).then((environment) => { | ||
if (environment) { | ||
this.setSceneEnvironment(environment.data); | ||
this.mainModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}) | ||
this.extraModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}); | ||
} | ||
this.setEnvMap(environment); | ||
resolve(); | ||
@@ -866,8 +899,3 @@ }); | ||
getEnvMapByName(envMap, processEnv).then((environment) => { | ||
if (environment) { | ||
this.setSceneEnvironment(environment.data); | ||
this.extraModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}); | ||
} | ||
this.setEnvMap(environment); | ||
resolve(); | ||
@@ -902,2 +930,20 @@ }); | ||
setEnvMap(environment) { | ||
if (environment) { | ||
this.setSceneEnvironment(environment.data); | ||
this.mainModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}) | ||
this.extraModels.forEach(modelRender => { | ||
modelRender.setModelMaterialEnvMap(environment.data); | ||
}); | ||
} | ||
} | ||
changeExtraModelsVisibility(visible) { | ||
this.extraModels.forEach(modelRender => { | ||
modelRender.setModelVisibility(visible); | ||
}); | ||
} | ||
start() { | ||
@@ -964,2 +1010,72 @@ return new Promise((resolve) => { | ||
calculateObjectSize(object) { | ||
var objectPosition = new THREE.Vector3(); | ||
object.getWorldPosition(objectPosition); // 获取物体的世界坐标 | ||
// 使用投影矩阵将物体坐标投影到屏幕坐标 | ||
objectPosition.project(this.camera); | ||
// 计算物体在Canvas上的大小(以像素为单位) | ||
var objectSize = { | ||
width: (objectPosition.x + 1) * 0.5 * 128, | ||
height: (-objectPosition.y + 1) * 0.5 * 128 | ||
}; | ||
return objectSize; | ||
} | ||
setCalculateObjectZoom(object) { | ||
return new Promise((resolve) => { | ||
let timer; | ||
const zoomLoop = () => { | ||
const size = this.calculateObjectSize(object); | ||
const max = Math.max(size.width, size.height); | ||
if (max < 118 && max > 98) { | ||
clearTimeout(timer); | ||
resolve(); | ||
} else if (max > 118) { | ||
this.cameraControls.zoom(new THREE.Vector3(0, 0, 1)); | ||
timer = setTimeout(zoomLoop, 30); | ||
} else if (max < 98) { | ||
this.cameraControls.zoom(new THREE.Vector3(0, 0, -1)); | ||
timer = setTimeout(zoomLoop, 30); | ||
} else { | ||
clearTimeout(timer); | ||
resolve(); | ||
} | ||
}; | ||
timer = setTimeout(zoomLoop, 30); | ||
}); | ||
} | ||
getDefaultIcon() { | ||
return new Promise((resolve) => { | ||
const canvas = this.getRenderDom(); | ||
canvas.style.background = 'rgba(255, 255, 255, 0)'; | ||
this.renderer.setClearAlpha(0); | ||
this.renderer.setClearColor(new THREE.Color(0xffffff), 0); | ||
this.scene.background = null; | ||
this.scene.environment = null; | ||
this.changeAmbientLight({ | ||
color: new THREE.Color(0xffffff), | ||
intensity: this.ambientLight.intensity * 2.4 <= 1 ? this.ambientLight.intensity * 2.4 : 1, | ||
}); | ||
this.focusModel(this.mainModels[0].getModel()); | ||
this.dom.width = 128; | ||
this.dom.height = 128; | ||
this.dom.style.width = `${128}px`; | ||
this.dom.style.height = `${128}px`; | ||
this.setSize(); | ||
this.setCalculateObjectZoom(this.mainModels[0].getModel()).then(() => { | ||
this.generateCurrFrameFlag = true; | ||
setTimeout(() => { | ||
resolve(this.currFrame); | ||
}, 100); | ||
}); | ||
}) | ||
} | ||
// tga 文件渲染能力 | ||
@@ -966,0 +1082,0 @@ static drawTgaCanvas(url) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
386550
10629