Important information: this site is currently scheduled to go offline indefinitely by December 1st 2023.
If you wish to donate to attempt the preservation of tools and software somewhere else before it goes down, check the GoFundMe

scarlet legacy fail import with noesis

Post questions about game models here, or help out others!
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

There are some issues with textures because I don't know where the material library is.
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

Ok, thanks for the support ^^
sorry xD but i've another question...
Seeing in your noesis plugin, i saw that also in ValkyrieSky,VoyageCenturyOnline,Travia2,talesOfFantasy and silkroad py there is the line sanae3d.sanae... The same of the first py of scarlet legacy... Can you tell me how can i resolve the problem? What i've to delete in there py plugin ?
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

Start by deleting the import line.
Then replace all references to `SanaeObject` with `Object`.

Then open Sanae.py, go to the `__init__` method and copy the thing over to the plugin's `__init__` method.

Look for any references to `read_string` and replace it with `noeStrFromBytes(...)`, and type in the appropriate call to read that many number of bytes.

There are probably other references to SanaeObject methods which will need to be replaced.
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

this is your plugin
https://www.dropbox.com/sh/7stlpd4qvkq3 ... oad_bms.py

and this is what i've done ... i don't know if it's correct but when i load bsm file from silkroad i've an error the error is:
-Line 62, in noepyLoadModel load single_model(data, mdlList)
-Line 49, in load single model parser = SanaeParser(data)
-Line 68, in __init__ super(sanaeParser, self).__init__(self,data)
TypeError: object.__init__() takes no parameters)

Code: Select all

from inc_noesis import *
import noesis
import rapi
import os

MODE = 0

def registerNoesisTypes():
    handle = noesis.register("Silkroad Online", ".bms")
    noesis.setHandlerTypeCheck(handle, noepyCheckType)
    noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
    noesis.logPopup()

    return 1

#check if it's this type based on the data
def noepyCheckType(data):
    
    if len(data) < 12:
        return 0
    bs = NoeBitStream(data)
    if bs.readBytes(12).decode("ASCII") != "JMXVBMS 0110":
        return 0
    return 1

def load_all_models(mdlList):
    '''Load all models'''

    #carry over from previous models
    matList = []
    texList = []

    dirPath = rapi.getDirForFilePath(rapi.getInputName())
    fileList = [file for file in os.listdir(dirPath) if file.lower().endswith(".bms")]
    for file in fileList:
        f = open(dirPath + file, 'rb')
        data2 = f.read()
        parser = SanaeParser(data2)
        parser.parse_file()
        matList.extend(parser.matList)
        texList.extend(parser.texList)
        mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(texList, matList))
    mdlList.append(mdl)    
    
def load_single_model(data, mdlList):
    '''Loads a single model. For testing purposes'''
    
    parser = SanaeParser(data)
    parser.parse_file()
    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(parser.texList, parser.matList))
    mdlList.append(mdl)       

def noepyLoadModel(data, mdlList):
    '''Load the model'''
    
    ctx = rapi.rpgCreateContext()
    if MODE == 1:
        load_all_models(mdlList)
    else:
        load_single_model(data, mdlList)
    return 1
class SanaeParser(object):
    
    def __init__(self, data):
       
        super(SanaeParser, self).__init__(self, data)
        
    def read_name(self):
        
        return self.noeStrFromBytes(self.inFile.readUInt())
    
    def parse_vertices(self, numVerts, vertType):
        
        if vertType == 0:
            vertBuff = self.inFile.readBytes(44*numVerts)
            rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 0)
            rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 12)
            rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 24)            
        elif vertType == 1024:
            vertBuff = self.inFile.readBytes(52*numVerts)
            rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 0)
            rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 12)
            rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 24)
            
    def parse_faces(self, numIdx):
        
        idxBuff = self.inFile.readBytes(2*numIdx)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
        
    def parse_bones(self, numBones, numVerts):
        
        for i in range(numBones):
            boneName = self.read_name()
        if numBones:
            for i in range(numVerts):
                b1 = self.inFile.readByte()
                w1 = self.inFile.readUShort()
                b2 = self.inFile.readByte()
                w2 = self.inFile.readUShort()
                
    def load_texture(self, matName):
        
        #texPath, ext = os.path.splitext(self.abspath.replace("mesh", "mtrl"))
        #f = open(texPath + ".ddj")
        try:
            f = open(self.basename + ".ddj", 'rb')
            f.seek(20)
            tex = rapi.loadTexByHandler(f.read(), ".dds")
            if tex is not None:
                tex.name = matName
                self.texList.append(tex)           
                
            material = NoeMaterial(matName, matName)
            self.matList.append(material)             
        except:
            pass        

    def parse_file(self):
        
        idstring = self.inFile.readBytes(12)
        offVerts, offBones, offFaces, unkOff1, unkOff2, ofsbbox, unkOff4, \
                 unk1, unk2, unkOff5, unk3, unk4, unk5, vertType, unk7 \
                 = self.inFile.read('15L')
        meshName = self.read_name()
        matName = self.read_name()
        
        self.inFile.readUInt()
        
        self.inFile.seek(offVerts)
        numVerts = self.inFile.readUInt()
        self.parse_vertices(numVerts, vertType)
        
        self.inFile.seek(offBones)
        numBones = self.inFile.readUInt()
        self.parse_bones(numBones, numVerts)
        
        self.inFile.seek(offFaces)
        numFaces = self.inFile.readUInt()
        
        rapi.rpgSetMaterial(matName)
        self.parse_faces(numFaces*3)

        self.load_texture(matName)
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

You have to replace the __init__ method completely with the one in the former superclass (SanaeObject)
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

i'm not english, i don't understand everything >.< can u give me an example?
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

Copy

Code: Select all

self.inFile = NoeBitStream(data)
self.animList = []
self.texList = []
self.matList = []
self.boneList = []
Replace in plugin

Code: Select all

super(SanaeParser, self).__init__(data)
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

this is the new code

Code: Select all

from inc_noesis import *
import noesis
import rapi
import os

MODE = 0

def registerNoesisTypes():
    handle = noesis.register("Silkroad Online", ".bms")
    noesis.setHandlerTypeCheck(handle, noepyCheckType)
    noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
    noesis.logPopup()

    return 1

#check if it's this type based on the data
def noepyCheckType(data):
    
    if len(data) < 12:
        return 0
    bs = NoeBitStream(data)
    if bs.readBytes(12).decode("ASCII") != "JMXVBMS 0110":
        return 0
    return 1

def load_all_models(mdlList):
    '''Load all models'''

    #carry over from previous models
    matList = []
    texList = []

    dirPath = rapi.getDirForFilePath(rapi.getInputName())
    fileList = [file for file in os.listdir(dirPath) if file.lower().endswith(".bms")]
    for file in fileList:
        f = open(dirPath + file, 'rb')
        data2 = f.read()
        parser = SanaeParser(data2)
        parser.parse_file()
        matList.extend(parser.matList)
        texList.extend(parser.texList)
        mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(texList, matList))
    mdlList.append(mdl)    
    
def load_single_model(data, mdlList):
    '''Loads a single model. For testing purposes'''
    
    parser = SanaeParser(data)
    parser.parse_file()
    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(parser.texList, parser.matList))
    mdlList.append(mdl)       

def noepyLoadModel(data, mdlList):
    '''Load the model'''
    
    ctx = rapi.rpgCreateContext()
    if MODE == 1:
        load_all_models(mdlList)
    else:
        load_single_model(data, mdlList)
    return 1
class SanaeParser(object):
    
    def __init__(self, data):
       
        super(SanaeParser, self).__init__(data)
        
                                self.inFile = NoeBitStream(data)
                                self.meshList = []
                                self.uvList = []
                                self.normList = []
                                self.vertList = []
                                self.idxList = []
                                self.animList = []
                                self.texList = []
                                self.matList = []
                                self.boneList = []
                                self.abspath = self._abspath()
                                self.dirpath = self._dirpath()
                                self.basename = self._basename()
                                self.filename = self._filename()        
    
    def read_name(self):
        
        return self.noeStrFromBytes(self.inFile.readUInt())
    
    def parse_vertices(self, numVerts, vertType):
        
        if vertType == 0:
            vertBuff = self.inFile.readBytes(44*numVerts)
            rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 0)
            rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 12)
            rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 24)            
        elif vertType == 1024:
            vertBuff = self.inFile.readBytes(52*numVerts)
            rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 0)
            rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 12)
            rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 24)
            
    def parse_faces(self, numIdx):
        
        idxBuff = self.inFile.readBytes(2*numIdx)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
        
    def parse_bones(self, numBones, numVerts):
        
        for i in range(numBones):
            boneName = self.read_name()
        if numBones:
            for i in range(numVerts):
                b1 = self.inFile.readByte()
                w1 = self.inFile.readUShort()
                b2 = self.inFile.readByte()
                w2 = self.inFile.readUShort()
                
    def load_texture(self, matName):
        
        #texPath, ext = os.path.splitext(self.abspath.replace("mesh", "mtrl"))
        #f = open(texPath + ".ddj")
        try:
            f = open(self.basename + ".ddj", 'rb')
            f.seek(20)
            tex = rapi.loadTexByHandler(f.read(), ".dds")
            if tex is not None:
                tex.name = matName
                self.texList.append(tex)           
                
            material = NoeMaterial(matName, matName)
            self.matList.append(material)             
        except:
            pass        

    def parse_file(self):
        
        idstring = self.inFile.readBytes(12)
        offVerts, offBones, offFaces, unkOff1, unkOff2, ofsbbox, unkOff4, \
                 unk1, unk2, unkOff5, unk3, unk4, unk5, vertType, unk7 \
                 = self.inFile.read('15L')
        meshName = self.read_name()
        matName = self.read_name()
        
        self.inFile.readUInt()
        
        self.inFile.seek(offVerts)
        numVerts = self.inFile.readUInt()
        self.parse_vertices(numVerts, vertType)
        
        self.inFile.seek(offBones)
        numBones = self.inFile.readUInt()
        self.parse_bones(numBones, numVerts)
        
        self.inFile.seek(offFaces)
        numFaces = self.inFile.readUInt()
        
        rapi.rpgSetMaterial(matName)
        self.parse_faces(numFaces*3)

        self.load_texture(matName)
but i don't know why but appear an error when i launch noesis:
silkroad py
line 70
self.inFile = NoeBitStream(data)
^
IndentationError: unexpected indent

I don't know what to do >.<
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

One issue with python is that all whitespace must be consistent. Either you use spaces, or you use tabs, but not both. And the amount of spacing must be exactly as expected.

You're supposed to delete the super call as well since you're no longer using it.
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

so... what i've to delete?
Sorry but i'm a noob in programming language
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

Just delete the line that says super.
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

I deleted the line says :<<super(SanaeParser, self).__init__(data)>>

but another error appear D:

line 78, __init__
self.adspath = self.:abspath()
AttibuteError: 'SanaeParser' object has no attribute '_abspath'
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

Most of them you don't need. I've only used matList and texList cause that's all I did.
The paths are not important either for the most part.
Drawing
mega-veteran
mega-veteran
Posts: 283
Joined: Wed Jan 11, 2012 10:21 pm
Has thanked: 43 times
Been thanked: 17 times

Re: scarlet legacy fail import with noesis

Post by Drawing »

Code: Select all

self.inFile = NoeBitStream(data)
self.animList = []
self.texList = []
self.matList = []
self.boneList = []
so do i have to delete "self.inFile = NoeBitStream(data),self.animList = []and self.boneList = []" ?
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Re: scarlet legacy fail import with noesis

Post by finale00 »

Try it out...? Your computer isn't going to explode if it doesn't work.
Post Reply