|
|
|
@ -9,57 +9,55 @@ import { IObservableValue } from 'mobx';
|
|
|
|
|
import { IDirProps } from './SourceManage/CommonPanel';
|
|
|
|
|
import { MaterialRendererSingle } from '../Editor/Asset/MaterialRenderer';
|
|
|
|
|
import { request, RequestStatus } from '../../Common/Request';
|
|
|
|
|
import { MaterialOut, deflate } from './SourceManage/SerializeMaterial';
|
|
|
|
|
import { MaterialOut, deflate, MaterialIn, inflate } from './SourceManage/SerializeMaterial';
|
|
|
|
|
import { AppToaster } from './Toaster';
|
|
|
|
|
import { Database } from '../../DatabaseServices/Database';
|
|
|
|
|
import { ImgsUrl, MaterialUrls } from '../../Common/HostUrl';
|
|
|
|
|
|
|
|
|
|
export interface MaterialContainerProps
|
|
|
|
|
{
|
|
|
|
|
mat: PhysicalMaterialRecord;
|
|
|
|
|
material: PhysicalMaterialRecord;
|
|
|
|
|
onlineId?: string;
|
|
|
|
|
isNew?: boolean;
|
|
|
|
|
isOpen?: IObservableValue<boolean>;
|
|
|
|
|
currentDir?: IDirProps;
|
|
|
|
|
getData?: () => void;
|
|
|
|
|
}
|
|
|
|
|
export interface MaterialContainerState
|
|
|
|
|
{
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const MATCONTENTID = "matContent";
|
|
|
|
|
|
|
|
|
|
export class MaterialContainer extends React.Component<MaterialContainerProps, MaterialContainerState> {
|
|
|
|
|
med: MaterialEditorLayout;
|
|
|
|
|
/**
|
|
|
|
|
* 材质球编辑器的容器
|
|
|
|
|
*/
|
|
|
|
|
export class MaterialContainer extends React.Component<MaterialContainerProps, { isOpen: boolean }> {
|
|
|
|
|
materialEditor: MaterialEditorLayout;
|
|
|
|
|
container: HTMLElement;
|
|
|
|
|
constructor(props)
|
|
|
|
|
{
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
isOpen: true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
handleOpen = () =>
|
|
|
|
|
{
|
|
|
|
|
if (this.props.isNew)
|
|
|
|
|
{
|
|
|
|
|
this.props.mat.Name = "新材质";
|
|
|
|
|
let db = new Database();
|
|
|
|
|
this.props.material.Name = db.MaterialTable.AllocateName();
|
|
|
|
|
db.MaterialTable.Add(this.props.material);
|
|
|
|
|
}
|
|
|
|
|
this.med = new MaterialEditorLayout(this.props.mat);
|
|
|
|
|
this.materialEditor = new MaterialEditorLayout(this.props.material);
|
|
|
|
|
}
|
|
|
|
|
handleClose = () =>
|
|
|
|
|
{
|
|
|
|
|
app.m_Editor.m_ModalManage.Clear();
|
|
|
|
|
if (this.props.isOpen)
|
|
|
|
|
this.props.isOpen.set(false);
|
|
|
|
|
if (this.props.onlineId)
|
|
|
|
|
{
|
|
|
|
|
//更新线上的值
|
|
|
|
|
console.log("update");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
handleUploadMat = async () =>
|
|
|
|
|
private handleUploadLogo = async () =>
|
|
|
|
|
{
|
|
|
|
|
let material = this.props.mat;
|
|
|
|
|
let material = this.props.material;
|
|
|
|
|
|
|
|
|
|
let blob = await MaterialRendererSingle.getBlob(material.Material);
|
|
|
|
|
let file = new File([blob], "blob.png", { type: blob.type });
|
|
|
|
@ -75,11 +73,17 @@ export class MaterialContainer extends React.Component<MaterialContainerProps, M
|
|
|
|
|
{
|
|
|
|
|
logoPath = data.images.path;
|
|
|
|
|
}
|
|
|
|
|
return logoPath;
|
|
|
|
|
}
|
|
|
|
|
handleUploadMtl = async () =>
|
|
|
|
|
{
|
|
|
|
|
let material = this.props.material;
|
|
|
|
|
|
|
|
|
|
let logoPath = await this.handleUploadLogo();
|
|
|
|
|
|
|
|
|
|
let materialJson = MaterialOut(material);
|
|
|
|
|
|
|
|
|
|
data = await request(MaterialUrls.create, {
|
|
|
|
|
let data = await request(MaterialUrls.create, {
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
dir_id: this.props.currentDir.id,
|
|
|
|
|
name: material.Name,
|
|
|
|
@ -95,6 +99,31 @@ export class MaterialContainer extends React.Component<MaterialContainerProps, M
|
|
|
|
|
}
|
|
|
|
|
this.handleClose();
|
|
|
|
|
}
|
|
|
|
|
handleUpdateMtl = async () =>
|
|
|
|
|
{
|
|
|
|
|
let material = this.props.material;
|
|
|
|
|
let logoPath = await this.handleUploadLogo();
|
|
|
|
|
let materialJson = MaterialOut(material);
|
|
|
|
|
|
|
|
|
|
let data = await request(MaterialUrls.update, {
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
material_id: this.props.onlineId,
|
|
|
|
|
name: material.Name,
|
|
|
|
|
logo: logoPath,
|
|
|
|
|
file: deflate(materialJson),
|
|
|
|
|
zip_type: "gzip",
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
if (data.err_code === RequestStatus.Ok)
|
|
|
|
|
{
|
|
|
|
|
await this.props.getData();
|
|
|
|
|
AppToaster.show({
|
|
|
|
|
message: "更新材质成功",
|
|
|
|
|
timeout: 1000
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
this.handleClose();
|
|
|
|
|
}
|
|
|
|
|
componentDidMount()
|
|
|
|
|
{
|
|
|
|
|
this.handleOpen();
|
|
|
|
@ -106,7 +135,7 @@ export class MaterialContainer extends React.Component<MaterialContainerProps, M
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
this.handleClose();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -115,12 +144,12 @@ export class MaterialContainer extends React.Component<MaterialContainerProps, M
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
this.handleClose();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}))
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
componentWillUnmount()
|
|
|
|
|
{
|
|
|
|
|
this.med.dispose();
|
|
|
|
|
this.materialEditor.dispose();
|
|
|
|
|
}
|
|
|
|
|
public render()
|
|
|
|
|
{
|
|
|
|
@ -168,7 +197,30 @@ export class MaterialContainer extends React.Component<MaterialContainerProps, M
|
|
|
|
|
<Button
|
|
|
|
|
className={Classes.INTENT_SUCCESS}
|
|
|
|
|
text="上传"
|
|
|
|
|
onClick={this.handleUploadMat} />
|
|
|
|
|
onClick={this.handleUploadMtl} />
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className={Classes.INTENT_DANGER}
|
|
|
|
|
text="取消"
|
|
|
|
|
onClick={this.handleClose} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
this.props.onlineId &&
|
|
|
|
|
<div className={Classes.DIALOG_FOOTER} >
|
|
|
|
|
<div
|
|
|
|
|
className={Classes.DIALOG_FOOTER_ACTIONS}
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: "flex-end",
|
|
|
|
|
padding: "10px 0",
|
|
|
|
|
width: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
className={Classes.INTENT_SUCCESS}
|
|
|
|
|
text="更新"
|
|
|
|
|
onClick={this.handleUpdateMtl} />
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className={Classes.INTENT_DANGER}
|
|
|
|
|